From a495cba15ef3205579b3461ffac960cb6f54d1c3 Mon Sep 17 00:00:00 2001 From: Nicholas Griffin Date: Sat, 27 Apr 2024 17:32:07 +0100 Subject: [PATCH] chore simplifying the conditional --- src/errors.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/errors.ts b/src/errors.ts index 8e6a948..29a5d14 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -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; }