Skip to content

Commit

Permalink
feat(service-error-classification): add 429 response as Throttling (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Nov 17, 2020
1 parent 75cd258 commit 9a62c0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 10 additions & 4 deletions packages/service-error-classification/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -90,21 +96,21 @@ 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);
});
});

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;
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion packages/service-error-classification/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down

0 comments on commit 9a62c0a

Please sign in to comment.