Accept HTTP/429 as a "rate-limited" status code

This commit is contained in:
Jon Chambers 2022-02-24 19:26:58 -05:00 committed by GitHub
parent 7431f151b2
commit 45289f519a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 156 additions and 16 deletions

View file

@ -31,6 +31,20 @@ describe('findRetryAfterTimeFromError', () => {
response: {},
}),
},
{
httpError: new HTTPError('Slow down', {
code: 429,
headers: {},
response: {},
}),
},
{
httpError: new HTTPError('Slow down', {
code: 429,
headers: { 'retry-after': 'garbage' },
response: {},
}),
},
].forEach(input => {
assert.strictEqual(findRetryAfterTimeFromError(input), MINUTE);
});
@ -64,6 +78,17 @@ describe('findRetryAfterTimeFromError', () => {
assert.strictEqual(findRetryAfterTimeFromError(input), 1234 * 1000);
});
it("finds the retry-after time on an HTTP error's response headers", () => {
const input = {
httpError: new HTTPError('Slow down', {
code: 429,
headers: { 'retry-after': '1234' },
response: {},
}),
};
assert.strictEqual(findRetryAfterTimeFromError(input), 1234 * 1000);
});
it('prefers the top-level response headers over an HTTP error', () => {
const input = {
responseHeaders: { 'retry-after': '1234' },
@ -75,4 +100,16 @@ describe('findRetryAfterTimeFromError', () => {
};
assert.strictEqual(findRetryAfterTimeFromError(input), 1234 * 1000);
});
it('prefers the top-level response headers over an HTTP error', () => {
const input = {
responseHeaders: { 'retry-after': '1234' },
httpError: new HTTPError('Slow down', {
code: 429,
headers: { 'retry-after': '999' },
response: {},
}),
};
assert.strictEqual(findRetryAfterTimeFromError(input), 1234 * 1000);
});
});