Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(service-error-classification): add 429 response as Throttling #1690

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/service-error-classification/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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,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;
@@ -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;
4 changes: 3 additions & 1 deletion packages/service-error-classification/src/index.ts
Original file line number Diff line number Diff line change
@@ -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) ||