Fixed the missing error message when logging invalid API key and improved the error message

This commit is contained in:
Eric Allam
2023-02-27 13:03:14 +00:00
parent 1579cdbfb2
commit 3a2cf0ddb7
4 changed files with 18 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/sdk": patch
---
Fixed the missing error message when logging invalid API key and improved the error message
+4 -1
View File
@@ -350,7 +350,10 @@ export class TriggerServer {
}
);
this.#socket.close(4001, "Client not authenticated");
this.#socket.close(
4001,
"Could not authenticate to the server because the API key is invalid"
);
}
}
+1 -1
View File
@@ -2,8 +2,8 @@
const logLevels = [
"disabled",
"log",
"error",
"log",
"warn",
"info",
"debug",
+8 -5
View File
@@ -16,6 +16,7 @@ import { Trigger, TriggerOptions } from "./trigger";
import { TriggerContext, TriggerFetch } from "./types";
import { generateErrorMessage, ErrorMessageOptions } from "zod-error";
import terminalLink from "terminal-link";
import chalk from "chalk";
const zodErrorMessageOptions: ErrorMessageOptions = {
delimiter: {
@@ -180,11 +181,11 @@ export class TriggerClient<TSchema extends z.ZodTypeAny> {
return;
}
this.#logger.error(`🚩 Could not connect to trigger.dev (code ${code})`);
if (reason) {
this.#logger.error("Reason:", reason);
}
this.#logger.error(
`${chalk.red("error")} Could not connect to trigger.dev${
reason ? `: ${reason}` : `(code ${code})`
}`
);
// If #isConnected is already false, that means we are already trying to reconnect
if (!this.#isConnected) return;
@@ -741,6 +742,8 @@ export class TriggerClient<TSchema extends z.ZodTypeAny> {
triggerTTL: this.#options.triggerTTL,
});
console.log(response);
if (!response) {
throw new Error("Could not initialize workflow with server");
}