Skip to content

Commit 18f1a6a

Browse files
committed
add recursion limit
1 parent c191326 commit 18f1a6a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/service-error-classification/src/index.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ describe("isTransientError", () => {
135135
checkForErrorType(isTransientError, { cause: { name } }, true);
136136
});
137137
});
138+
139+
it("should limit recursion to 10 depth", () => {
140+
const error = { cause: null } as SdkError;
141+
error.cause = error;
142+
checkForErrorType(isTransientError, { cause: error }, false);
143+
});
138144
});
139145

140146
describe("isServerError", () => {

packages/service-error-classification/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ export const isThrottlingError = (error: SdkError) =>
3131
* cause where the NodeHttpHandler does not decorate the Error with
3232
* the name "TimeoutError" to be checked by the TRANSIENT_ERROR_CODES condition.
3333
*/
34-
export const isTransientError = (error: SdkError) =>
34+
export const isTransientError = (error: SdkError, depth = 0) =>
3535
isClockSkewCorrectedError(error) ||
3636
TRANSIENT_ERROR_CODES.includes(error.name) ||
3737
NODEJS_TIMEOUT_ERROR_CODES.includes((error as { code?: string })?.code || "") ||
3838
TRANSIENT_ERROR_STATUS_CODES.includes(error.$metadata?.httpStatusCode || 0) ||
39-
(error.cause !== undefined && isTransientError(error.cause));
39+
(error.cause !== undefined && depth <= 10 && isTransientError(error.cause, depth + 1));
4040

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

0 commit comments

Comments
 (0)