Skip to content

Commit

Permalink
chore simplifying the conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasgriffintn committed Apr 27, 2024
1 parent 3224cc5 commit a495cba
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,28 @@ class StandardError extends Error {
}
}

/**
* List of SQS error codes that are considered connection errors.
*/
const CONNECTION_ERRORS = [
"CredentialsError",
"UnknownEndpoint",
"AWS.SimpleQueueService.NonExistentQueue",
"CredentialsProviderError",
"InvalidAddress",
"InvalidSecurity",
"QueueDoesNotExist",
"RequestThrottled",
"OverLimit",
];

/**
* Checks if the error provided should be treated as a connection error.
* @param err The error that was received.
*/
function isConnectionError(err: Error): boolean {
if (err instanceof SQSError) {
return (
err.statusCode === 403 ||
err.code === "CredentialsError" ||
err.code === "UnknownEndpoint" ||
err.code === "AWS.SimpleQueueService.NonExistentQueue" ||
err.code === "CredentialsProviderError" ||
err.code === "InvalidAddress" ||
err.code === "InvalidSecurity" ||
err.code === "QueueDoesNotExist" ||
err.code === "RequestThrottled" ||
err.code === "OverLimit"
);
return err.statusCode === 403 || CONNECTION_ERRORS.includes(err.code);
}
return false;
}
Expand Down

0 comments on commit a495cba

Please sign in to comment.