Skip to content

Commit 9a62c0a

Browse files
authored
feat(service-error-classification): add 429 response as Throttling (#1690)
1 parent 75cd258 commit 9a62c0a

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ describe("isClockSkewError", () => {
5656
});
5757

5858
describe("isThrottlingError", () => {
59+
[429].forEach((httpStatusCode) => {
60+
it(`should declare error with the HTTP Status Code "${httpStatusCode}" to be a Throttling error`, () => {
61+
checkForErrorType(isTransientError, { httpStatusCode }, false);
62+
});
63+
});
64+
5965
THROTTLING_ERROR_CODES.forEach((name) => {
6066
it(`should declare error with the name "${name}" to be a Throttling error`, () => {
6167
checkForErrorType(isThrottlingError, { name }, true);
@@ -90,21 +96,21 @@ describe("isThrottlingError", () => {
9096

9197
describe("isTransientError", () => {
9298
TRANSIENT_ERROR_CODES.forEach((name) => {
93-
it(`should declare error with the name "${name}" to be a Throttling error`, () => {
99+
it(`should declare error with the name "${name}" to be a Transient error`, () => {
94100
checkForErrorType(isTransientError, { name }, true);
95101
});
96102
});
97103

98104
TRANSIENT_ERROR_STATUS_CODES.forEach((httpStatusCode) => {
99-
it(`should declare error with the HTTP Status Code "${httpStatusCode}" to be a Throttling error`, () => {
105+
it(`should declare error with the HTTP Status Code "${httpStatusCode}" to be a Transient error`, () => {
100106
checkForErrorType(isTransientError, { httpStatusCode }, true);
101107
});
102108
});
103109

104110
while (true) {
105111
const name = Math.random().toString(36).substring(2);
106112
if (!TRANSIENT_ERROR_CODES.includes(name)) {
107-
it(`should not declare error with the name "${name}" to be a Throttling error`, () => {
113+
it(`should not declare error with the name "${name}" to be a Transient error`, () => {
108114
checkForErrorType(isTransientError, { name }, false);
109115
});
110116
break;
@@ -114,7 +120,7 @@ describe("isTransientError", () => {
114120
while (true) {
115121
const httpStatusCode = Math.ceil(Math.random() * 10 ** 3);
116122
if (!TRANSIENT_ERROR_STATUS_CODES.includes(httpStatusCode)) {
117-
it(`should declare error with the HTTP Status Code "${httpStatusCode}" to be a Throttling error`, () => {
123+
it(`should declare error with the HTTP Status Code "${httpStatusCode}" to be a Transient error`, () => {
118124
checkForErrorType(isTransientError, { httpStatusCode }, false);
119125
});
120126
break;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export const isRetryableByTrait = (error: SdkError) => error.$retryable !== unde
1212
export const isClockSkewError = (error: SdkError) => CLOCK_SKEW_ERROR_CODES.includes(error.name);
1313

1414
export const isThrottlingError = (error: SdkError) =>
15-
THROTTLING_ERROR_CODES.includes(error.name) || error.$retryable?.throttling == true;
15+
error.$metadata?.httpStatusCode === 429 ||
16+
THROTTLING_ERROR_CODES.includes(error.name) ||
17+
error.$retryable?.throttling == true;
1618

1719
export const isTransientError = (error: SdkError) =>
1820
TRANSIENT_ERROR_CODES.includes(error.name) ||

0 commit comments

Comments
 (0)