diff --git a/lib/platform/github/gh-got-wrapper.js b/lib/platform/github/gh-got-wrapper.js index e7f6ca9ee5c69b315edfff85e3275df2c79c2edf..4d7758fb65c18afb7cd8e2db6f8b22cca68b2273 100644 --- a/lib/platform/github/gh-got-wrapper.js +++ b/lib/platform/github/gh-got-wrapper.js @@ -96,18 +96,17 @@ async function get(path, opts, retries = 5) { } else if ( err.statusCode === 401 && err.message && - err.message.indexOf('Bad credentials') !== -1 + err.message.includes('Bad credentials') ) { - if (retries > 0) { - logger.info( - { statusCode: err.statusCode, message: err.message }, - `Retrying request` - ); - - await delay(5000 / retries); - - return get(path, opts, retries - 1); - } + logger.debug( + { + err, + message: err.message, + body: err.response ? err.response.body : undefined, + }, + 'Bad credentials' + ); + throw new Error('bad-credentials'); } throw err; } diff --git a/test/platform/github/gh-got-wrapper.spec.js b/test/platform/github/gh-got-wrapper.spec.js index 2d5dba292d8930257191f98289863051c0074212..21081254c64c9086e31d7af7615179d89c30d289 100644 --- a/test/platform/github/gh-got-wrapper.spec.js +++ b/test/platform/github/gh-got-wrapper.spec.js @@ -74,6 +74,22 @@ describe('platform/gh-got-wrapper', () => { } expect(e).toBeDefined(); }); + it('should throw Bad credentials', async () => { + ghGot.mockImplementationOnce(() => + Promise.reject({ + statusCode: 401, + message: 'Bad credentials. (401)', + }) + ); + let e; + try { + await get('some-url'); + } catch (err) { + e = err; + } + expect(e).toBeDefined(); + expect(e.message).toEqual('bad-credentials'); + }); it('should retry 502s', async () => { ghGot.mockImplementationOnce(() => Promise.reject({ @@ -118,8 +134,7 @@ describe('platform/gh-got-wrapper', () => { ); ghGot.mockImplementationOnce(() => Promise.reject({ - statusCode: 401, - message: 'Bad credentials', + statusCode: 502, }) ); ghGot.mockImplementationOnce(() =>