mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
fix: retry 429 with retry-after
This commit is contained in:
parent
11d5a8b02e
commit
1210300dd2
2 changed files with 11 additions and 4 deletions
|
@ -215,10 +215,14 @@ async function getDependency(name, retries = 5) {
|
|||
return getDependency(name, retries - 1);
|
||||
}
|
||||
if (err.statusCode === 429) {
|
||||
// This is bad if it ever happens, so we should error
|
||||
if (retries <= 0) {
|
||||
logger.error({ err }, 'npm registry failure: too many requests');
|
||||
throw new Error('registry-failure');
|
||||
}
|
||||
const retryAfter = err.headers['retry-after'] || 30;
|
||||
await delay(1000 * (retryAfter + 1));
|
||||
return getDependency(name, retries - 1);
|
||||
}
|
||||
if (err.statusCode === 408) {
|
||||
if (retries <= 0) {
|
||||
logger.warn({ err }, 'npm registry failure: timeout, retries=0');
|
||||
|
|
|
@ -88,12 +88,15 @@ describe('api/npm', () => {
|
|||
expect(e).toBeDefined();
|
||||
});
|
||||
it('should throw error for 429', async () => {
|
||||
nock('https://registry.npmjs.org')
|
||||
.get('/foobar')
|
||||
.reply(429);
|
||||
nock('https://registry.npmjs.org')
|
||||
.get('/foobar')
|
||||
.reply(429);
|
||||
let e;
|
||||
try {
|
||||
await npm.getDependency('foobar');
|
||||
await npm.getDependency('foobar', 1);
|
||||
} catch (err) {
|
||||
e = err;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue