Skip to content

Commit

Permalink
add recursion limit
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Nov 26, 2024
1 parent c191326 commit 18f1a6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/service-error-classification/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ describe("isTransientError", () => {
checkForErrorType(isTransientError, { cause: { name } }, true);
});
});

it("should limit recursion to 10 depth", () => {
const error = { cause: null } as SdkError;
error.cause = error;
checkForErrorType(isTransientError, { cause: error }, false);
});
});

describe("isServerError", () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/service-error-classification/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export const isThrottlingError = (error: SdkError) =>
* 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) =>
export const isTransientError = (error: SdkError, depth = 0) =>
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) ||
(error.cause !== undefined && isTransientError(error.cause));
(error.cause !== undefined && depth <= 10 && isTransientError(error.cause, depth + 1));

export const isServerError = (error: SdkError) => {
if (error.$metadata?.httpStatusCode !== undefined) {
Expand Down

0 comments on commit 18f1a6a

Please sign in to comment.