Skip to content

Commit

Permalink
add support for error cause in transient error checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmthf committed Nov 26, 2024
1 parent f4e1a45 commit c191326
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/good-dots-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@smithy/service-error-classification": patch
"@smithy/types": patch
---

add support for error cause in transient error checks
10 changes: 9 additions & 1 deletion packages/service-error-classification/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ const checkForErrorType = (
name?: string;
httpStatusCode?: number;
$retryable?: RetryableTrait;
cause?: Partial<Error>;
},
errorTypeResult: boolean
) => {
const { name, httpStatusCode, $retryable } = options;
const { name, httpStatusCode, $retryable, cause } = options;
const error = Object.assign(new Error(), {
name,
$metadata: { httpStatusCode },
$retryable,
cause,
});
expect(isErrorTypeFunc(error as SdkError)).toBe(errorTypeResult);
};
Expand Down Expand Up @@ -127,6 +129,12 @@ describe("isTransientError", () => {
break;
}
}

TRANSIENT_ERROR_CODES.forEach((name) => {
it(`should declare error with cause with the name "${name}" to be a Transient error`, () => {
checkForErrorType(isTransientError, { cause: { name } }, true);
});
});
});

describe("isServerError", () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/service-error-classification/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const isTransientError = (error: SdkError) =>
isClockSkewCorrectedError(error) ||
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);
TRANSIENT_ERROR_STATUS_CODES.includes(error.$metadata?.httpStatusCode || 0) ||
(error.cause !== undefined && isTransientError(error.cause));

export const isServerError = (error: SdkError) => {
if (error.$metadata?.httpStatusCode !== undefined) {
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ export type SdkError = Error &
*/
readonly clockSkewCorrected?: true;
};
cause?: Error;
};

0 comments on commit c191326

Please sign in to comment.