diff --git a/backend/src/server/plugins/error-handler.ts b/backend/src/server/plugins/error-handler.ts index 6b51f04f7..34766f79e 100644 --- a/backend/src/server/plugins/error-handler.ts +++ b/backend/src/server/plugins/error-handler.ts @@ -46,6 +46,7 @@ export const fastifyErrHandler = fastifyPlugin(async (server: FastifyZodProvider }); // Handle JWT errors and make them more human-readable for the end-user. } else if (error instanceof JsonWebTokenError) { + // We wan't to return a slightly different message if the request is coming from the CLI. This is because we're able to provide more specific information to the user in that case. const isCliRequest = req.headers["user-agent"] === UserAgentType.CLI; const message = (() => { @@ -54,13 +55,13 @@ export const fastifyErrHandler = fastifyPlugin(async (server: FastifyZodProvider } if (error.message === JWTErrors.JwtMalformed) { if (isCliRequest) { - return "The access token is malformed. Are you sure the token you are using is correct? Check the INFISICAL_TOKEN environment variable, or the --token flag. If you are using user-login, please run [infisical login] to re-authenticate."; + return "The access token is malformed. Are you sure the token you are using is correct? Check the INFISICAL_TOKEN environment variable, or the --token flag. If you are using user-login, please run [infisical login] to re-authenticate. Please ensure that the INFISICAL_TOKEN variable is not set, if you are not intentionally using it."; } return "The access token is malformed. Please ensure that the token is in the correct format and try again."; } if (error.message === JWTErrors.InvalidAlgorithm) { if (isCliRequest) { - return "Invalid algorithm. Are you sure you are using the correct authentication method? Make sure to check that you don't have the INFISICAL_TOKEN variable set in your environment variables. If you are intentionally using the INFISICAL_TOKEN variable, make sure you are using the correct token." as const; + return "Invalid algorithm. Are you sure you are using the correct authentication method? Make sure to check that you don't have the INFISICAL_TOKEN variable set in your environment variables. If you are intentionally using the INFISICAL_TOKEN variable, make sure you are using the correct token."; } return "The access token is signed with an invalid algorithm. Please ensure that the token is in the correct format and try again. We recommend obtaining a new token."; }