Skip to content

Commit 18e37df

Browse files
committed
fix(service-error-classification): add message checks
1 parent 7c31af1 commit 18e37df

File tree

1 file changed

+23
-1
lines changed
  • packages/service-error-classification/src

1 file changed

+23
-1
lines changed

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

+23-1
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,7 +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) ||
39-
error instanceof TypeError ||
61+
isBrowserNetworkError(error) ||
4062
(error.cause !== undefined && depth <= 10 && isTransientError(error.cause, depth + 1));
4163

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

0 commit comments

Comments
 (0)