Skip to content

fix(service-error-classification): add TypeError as transient error #1574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/large-donkeys-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/service-error-classification": patch
---

add browser connection issues as transient errors to retry on
23 changes: 23 additions & 0 deletions packages/service-error-classification/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ export const isClockSkewError = (error: SdkError) => CLOCK_SKEW_ERROR_CODES.incl
*/
export const isClockSkewCorrectedError = (error: SdkError) => error.$metadata?.clockSkewCorrected;

/**
*
* @internal
*/
export const isBrowserNetworkError = (error: SdkError) => {
const errorMessages = new Set([
Copy link
Contributor Author

@siddsriv siddsriv May 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this constant could be placed somewhere else, like the constants file in the same dir. I'd like this here since:

  1. these are not as strong a check as error codes or status codes, so I want to keep them away from other constants
  2. this function and its hacky message checks will be easily(-ier?) visible in the future if someone is taking a look at transient errors.

"Failed to fetch", // Chrome
"NetworkError when attempting to fetch resource", // Firefox
"The Internet connection appears to be offline", // Safari 16
"Load failed", // Safari 17+
"Network request failed", // `cross-fetch`
]);

const isValid = error && error instanceof TypeError;

if (!isValid) {
return false;
}

return errorMessages.has(error.message);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing a check for messages as well to avoid unintended TypeErrors from being retried

};

export const isThrottlingError = (error: SdkError) =>
error.$metadata?.httpStatusCode === 429 ||
THROTTLING_ERROR_CODES.includes(error.name) ||
Expand All @@ -36,6 +58,7 @@ export const isTransientError = (error: SdkError, depth = 0): boolean =>
TRANSIENT_ERROR_CODES.includes(error.name) ||
NODEJS_TIMEOUT_ERROR_CODES.includes((error as { code?: string })?.code || "") ||
TRANSIENT_ERROR_STATUS_CODES.includes(error.$metadata?.httpStatusCode || 0) ||
isBrowserNetworkError(error) ||
(error.cause !== undefined && depth <= 10 && isTransientError(error.cause, depth + 1));

export const isServerError = (error: SdkError) => {
Expand Down