mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-19 16:08:34 +01:00
Accept HTTP/429 as a "rate-limited" status code
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user