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

fix(github): gracefully handle integration unauthorized

parent 91e48147
No related branches found
No related tags found
No related merge requests found
......@@ -159,11 +159,11 @@ async function get(path, options, retries = 5) {
throw err;
} else if (
err.statusCode === 403 &&
!(
err.message &&
err.message.startsWith('Resource not accessible by integration')
)
err.message &&
err.message.startsWith('Resource not accessible by integration')
) {
throw new Error('integration-unauthorized');
} else if (err.statusCode === 403) {
if (retries > 0) {
logger.info(
{ statusCode: err.statusCode, message: err.message },
......
......@@ -299,6 +299,10 @@ async function processBranch(branchConfig, prHourlyLimitReached, packageFiles) {
logger.debug('Passing bad-credentials error up');
throw err;
}
if (err.message === 'integration-unauthorized') {
logger.debug('Passing integration-unauthorized error up');
throw err;
}
if (err.message === 'lockfile-error') {
logger.debug('Passing lockfile-error up');
throw err;
......
......@@ -94,6 +94,11 @@ async function handleError(config, err) {
delete config.branchList; // eslint-disable-line no-param-reassign
return err.message;
}
if (err.message === 'integration-unauthorized') {
logger.warn('Integration unauthorized - aborting');
delete config.branchList; // eslint-disable-line no-param-reassign
return err.message;
}
if (err.message === 'lockfile-error') {
delete config.branchList; // eslint-disable-line no-param-reassign
logger.info('Lock file error - aborting');
......
......@@ -314,4 +314,20 @@ describe('platform/gh-got-wrapper', () => {
expect(e).toBeDefined();
expect(e.message).toEqual('platform-failure');
});
it('should throw for unauthorized integration', async () => {
ghGot.mockImplementationOnce(() =>
Promise.reject({
statusCode: 403,
message: 'Resource not accessible by integration (403)',
})
);
let e;
try {
await get('some-url', {}, 0);
} catch (err) {
e = err;
}
expect(e).toBeDefined();
expect(e.message).toEqual('integration-unauthorized');
});
});
......@@ -30,6 +30,7 @@ describe('workers/repository/error', () => {
'platform-failure',
'no-vulnerability-alerts',
'cannot-fork',
'integration-unauthorized',
];
errors.forEach(err => {
it(`errors ${err}`, async () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment