Skip to content

Commit 89bde09

Browse files
authored
fix(service-error-classification): add TypeError as transient error (#1574)
* fix(service-error-classification): add TypeError as transient error * chore(changeset): changeset * fix(service-error-classification): add message checks
1 parent 57e0a48 commit 89bde09

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

.changeset/large-donkeys-notice.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/service-error-classification": patch
3+
---
4+
5+
add browser connection issues as transient errors to retry on

packages/service-error-classification/src/index.ts

+23
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@ export const isClockSkewError = (error: SdkError) => CLOCK_SKEW_ERROR_CODES.incl
2020
*/
2121
export const isClockSkewCorrectedError = (error: SdkError) => error.$metadata?.clockSkewCorrected;
2222

23+
/**
24+
*
25+
* @internal
26+
*/
27+
export const isBrowserNetworkError = (error: SdkError) => {
28+
const errorMessages = new Set([
29+
"Failed to fetch", // Chrome
30+
"NetworkError when attempting to fetch resource", // Firefox
31+
"The Internet connection appears to be offline", // Safari 16
32+
"Load failed", // Safari 17+
33+
"Network request failed", // `cross-fetch`
34+
]);
35+
36+
const isValid = error && error instanceof TypeError;
37+
38+
if (!isValid) {
39+
return false;
40+
}
41+
42+
return errorMessages.has(error.message);
43+
};
44+
2345
export const isThrottlingError = (error: SdkError) =>
2446
error.$metadata?.httpStatusCode === 429 ||
2547
THROTTLING_ERROR_CODES.includes(error.name) ||
@@ -36,6 +58,7 @@ export const isTransientError = (error: SdkError, depth = 0): boolean =>
3658
TRANSIENT_ERROR_CODES.includes(error.name) ||
3759
NODEJS_TIMEOUT_ERROR_CODES.includes((error as { code?: string })?.code || "") ||
3860
TRANSIENT_ERROR_STATUS_CODES.includes(error.$metadata?.httpStatusCode || 0) ||
61+
isBrowserNetworkError(error) ||
3962
(error.cause !== undefined && depth <= 10 && isTransientError(error.cause, depth + 1));
4063

4164
export const isServerError = (error: SdkError) => {

0 commit comments

Comments
 (0)