@@ -20,6 +20,28 @@ export const isClockSkewError = (error: SdkError) => CLOCK_SKEW_ERROR_CODES.incl
20
20
*/
21
21
export const isClockSkewCorrectedError = ( error : SdkError ) => error . $metadata ?. clockSkewCorrected ;
22
22
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
+
23
45
export const isThrottlingError = ( error : SdkError ) =>
24
46
error . $metadata ?. httpStatusCode === 429 ||
25
47
THROTTLING_ERROR_CODES . includes ( error . name ) ||
@@ -36,7 +58,7 @@ export const isTransientError = (error: SdkError, depth = 0): boolean =>
36
58
TRANSIENT_ERROR_CODES . includes ( error . name ) ||
37
59
NODEJS_TIMEOUT_ERROR_CODES . includes ( ( error as { code ?: string } ) ?. code || "" ) ||
38
60
TRANSIENT_ERROR_STATUS_CODES . includes ( error . $metadata ?. httpStatusCode || 0 ) ||
39
- error instanceof TypeError ||
61
+ isBrowserNetworkError ( error ) ||
40
62
( error . cause !== undefined && depth <= 10 && isTransientError ( error . cause , depth + 1 ) ) ;
41
63
42
64
export const isServerError = ( error : SdkError ) => {
0 commit comments