From 4f0a95477e7c419d8fb8d56fc021a4b210ab4e50 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Mon, 16 Nov 2020 19:39:36 +0000 Subject: [PATCH] feat(service-error-classification): retry statusCode 429 --- .../service-error-classification/src/index.spec.ts | 14 ++++++++++---- packages/service-error-classification/src/index.ts | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/service-error-classification/src/index.spec.ts b/packages/service-error-classification/src/index.spec.ts index 250dd41bce1d..168f3e8f0b41 100644 --- a/packages/service-error-classification/src/index.spec.ts +++ b/packages/service-error-classification/src/index.spec.ts @@ -56,6 +56,12 @@ describe("isClockSkewError", () => { }); describe("isThrottlingError", () => { + [429].forEach((httpStatusCode) => { + it(`should declare error with the HTTP Status Code "${httpStatusCode}" to be a Throttling error`, () => { + checkForErrorType(isTransientError, { httpStatusCode }, false); + }); + }); + THROTTLING_ERROR_CODES.forEach((name) => { it(`should declare error with the name "${name}" to be a Throttling error`, () => { checkForErrorType(isThrottlingError, { name }, true); @@ -90,13 +96,13 @@ describe("isThrottlingError", () => { describe("isTransientError", () => { TRANSIENT_ERROR_CODES.forEach((name) => { - it(`should declare error with the name "${name}" to be a Throttling error`, () => { + it(`should declare error with the name "${name}" to be a Transient error`, () => { checkForErrorType(isTransientError, { name }, true); }); }); TRANSIENT_ERROR_STATUS_CODES.forEach((httpStatusCode) => { - it(`should declare error with the HTTP Status Code "${httpStatusCode}" to be a Throttling error`, () => { + it(`should declare error with the HTTP Status Code "${httpStatusCode}" to be a Transient error`, () => { checkForErrorType(isTransientError, { httpStatusCode }, true); }); }); @@ -104,7 +110,7 @@ describe("isTransientError", () => { while (true) { const name = Math.random().toString(36).substring(2); if (!TRANSIENT_ERROR_CODES.includes(name)) { - it(`should not declare error with the name "${name}" to be a Throttling error`, () => { + it(`should not declare error with the name "${name}" to be a Transient error`, () => { checkForErrorType(isTransientError, { name }, false); }); break; @@ -114,7 +120,7 @@ describe("isTransientError", () => { while (true) { const httpStatusCode = Math.ceil(Math.random() * 10 ** 3); if (!TRANSIENT_ERROR_STATUS_CODES.includes(httpStatusCode)) { - it(`should declare error with the HTTP Status Code "${httpStatusCode}" to be a Throttling error`, () => { + it(`should declare error with the HTTP Status Code "${httpStatusCode}" to be a Transient error`, () => { checkForErrorType(isTransientError, { httpStatusCode }, false); }); break; diff --git a/packages/service-error-classification/src/index.ts b/packages/service-error-classification/src/index.ts index ee141d6aae37..5edcdf297c44 100644 --- a/packages/service-error-classification/src/index.ts +++ b/packages/service-error-classification/src/index.ts @@ -12,7 +12,9 @@ export const isRetryableByTrait = (error: SdkError) => error.$retryable !== unde export const isClockSkewError = (error: SdkError) => CLOCK_SKEW_ERROR_CODES.includes(error.name); export const isThrottlingError = (error: SdkError) => - THROTTLING_ERROR_CODES.includes(error.name) || error.$retryable?.throttling == true; + error.$metadata?.httpStatusCode === 429 || + THROTTLING_ERROR_CODES.includes(error.name) || + error.$retryable?.throttling == true; export const isTransientError = (error: SdkError) => TRANSIENT_ERROR_CODES.includes(error.name) ||