Skip to content
Snippets Groups Projects
Commit fc203bcc authored by Rhys Arkins's avatar Rhys Arkins
Browse files

refactor(github): do not retry 401 Bad Credentials

parent 71a8fb89
No related branches found
No related tags found
No related merge requests found
...@@ -96,18 +96,17 @@ async function get(path, opts, retries = 5) { ...@@ -96,18 +96,17 @@ async function get(path, opts, retries = 5) {
} else if ( } else if (
err.statusCode === 401 && err.statusCode === 401 &&
err.message && err.message &&
err.message.indexOf('Bad credentials') !== -1 err.message.includes('Bad credentials')
) { ) {
if (retries > 0) { logger.debug(
logger.info( {
{ statusCode: err.statusCode, message: err.message }, err,
`Retrying request` message: err.message,
); body: err.response ? err.response.body : undefined,
},
await delay(5000 / retries); 'Bad credentials'
);
return get(path, opts, retries - 1); throw new Error('bad-credentials');
}
} }
throw err; throw err;
} }
......
...@@ -74,6 +74,22 @@ describe('platform/gh-got-wrapper', () => { ...@@ -74,6 +74,22 @@ describe('platform/gh-got-wrapper', () => {
} }
expect(e).toBeDefined(); 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 () => { it('should retry 502s', async () => {
ghGot.mockImplementationOnce(() => ghGot.mockImplementationOnce(() =>
Promise.reject({ Promise.reject({
...@@ -118,8 +134,7 @@ describe('platform/gh-got-wrapper', () => { ...@@ -118,8 +134,7 @@ describe('platform/gh-got-wrapper', () => {
); );
ghGot.mockImplementationOnce(() => ghGot.mockImplementationOnce(() =>
Promise.reject({ Promise.reject({
statusCode: 401, statusCode: 502,
message: 'Bad credentials',
}) })
); );
ghGot.mockImplementationOnce(() => ghGot.mockImplementationOnce(() =>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment