-
Notifications
You must be signed in to change notification settings - Fork 595
/
Copy pathindex.ts
29 lines (24 loc) · 1.12 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { SdkError } from "@aws-sdk/types";
import {
CLOCK_SKEW_ERROR_CODES,
NODEJS_TIMEOUT_ERROR_CODES,
THROTTLING_ERROR_CODES,
TRANSIENT_ERROR_CODES,
TRANSIENT_ERROR_STATUS_CODES,
} from "./constants";
export const isRetryableByTrait = (error: SdkError) => error.$retryable !== undefined;
export const isClockSkewError = (error: SdkError) => CLOCK_SKEW_ERROR_CODES.includes(error.name);
export const isThrottlingError = (error: SdkError) =>
error.$metadata?.httpStatusCode === 429 ||
THROTTLING_ERROR_CODES.includes(error.name) ||
error.$retryable?.throttling == true;
/**
* Though NODEJS_TIMEOUT_ERROR_CODES are platform specific, they are
* included here because there is an error scenario with unknown root
* cause where the NodeHttpHandler does not decorate the Error with
* the name "TimeoutError" to be checked by the TRANSIENT_ERROR_CODES condition.
*/
export const isTransientError = (error: SdkError) =>
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);