refactor(github): retry abuse detection ony once

This commit is contained in:
Rhys Arkins 2018-10-28 14:46:52 +01:00
parent 9295efecdd
commit 99014ff973

View file

@ -117,24 +117,27 @@ async function get(path, options, retries = 5) {
throw new Error('platform-failure'); throw new Error('platform-failure');
} }
if ( if (
retries > 0 &&
err.statusCode === 403 && err.statusCode === 403 &&
err.message && err.message &&
err.message.startsWith('You have triggered an abuse detection mechanism') err.message.startsWith('You have triggered an abuse detection mechanism')
) { ) {
logger.info( if (retries > 0) {
{ logger.info(
headers: err.headers, {
path, headers: err.headers,
statusCode: err.statusCode, path,
message: err.message, statusCode: err.statusCode,
}, message: err.message,
`Retrying request` },
); `Retrying request`
);
await delay(180000 / (retries * retries)); await delay(180000 / (retries * retries));
return get(path, opts, retries - 1); return get(path, opts, 0);
}
// istanbul ignore next
throw new Error('platform-failure');
} }
if ( if (
err.statusCode === 403 && err.statusCode === 403 &&