Skip to content

Commit

Permalink
fix(node-http-handler): check for error code in isTransientError (#4018)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Oct 5, 2022
1 parent 6ff07bd commit ab0e7be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/node-http-handler/src/constants.ts
@@ -1,4 +1,5 @@
/**
* Node.js system error codes that indicate timeout.
* @deprecated use NODEJS_TIMEOUT_ERROR_CODES from @aws-sdk/service-error-classification/constants
*/
export const NODEJS_TIMEOUT_ERROR_CODES = ["ECONNRESET", "EPIPE", "ETIMEDOUT"];
5 changes: 5 additions & 0 deletions packages/service-error-classification/src/constants.ts
Expand Up @@ -45,3 +45,8 @@ export const TRANSIENT_ERROR_CODES = ["AbortError", "TimeoutError", "RequestTime
* Error codes that indicate transient issues
*/
export const TRANSIENT_ERROR_STATUS_CODES = [500, 502, 503, 504];

/**
* Node.js system error codes that indicate timeout.
*/
export const NODEJS_TIMEOUT_ERROR_CODES = ["ECONNRESET", "EPIPE", "ETIMEDOUT"];
8 changes: 8 additions & 0 deletions packages/service-error-classification/src/index.ts
Expand Up @@ -2,6 +2,7 @@ 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,
Expand All @@ -16,6 +17,13 @@ export const isThrottlingError = (error: SdkError) =>
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);

0 comments on commit ab0e7be

Please sign in to comment.