Skip to content

Commit

Permalink
do up to 5 attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Sep 1, 2020
1 parent 7a2c4c0 commit 927bab6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/kbn-release-notes/src/lib/pr_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ export class PrApi {
*/
private async gqlRequest(query: DocumentNode, variables: Record<string, unknown> = {}) {
let attempt = 0;
const baseTimeout = 2000;

while (true) {
attempt += 1;
Expand All @@ -208,21 +207,21 @@ export class PrApi {

return resp.data;
} catch (error) {
if (!isAxiosResponseError(error) || !(error.response.status >= 500)) {
if (!isAxiosResponseError(error) || error.response.status < 500) {
// rethrow error unless it is a 500+ response from github
throw error;
}

const { status, data } = error.response;
const resp = inspect(data);

if (attempt >= 3) {
if (attempt === 5) {
throw new Error(
`${status} response from Github, attempted request ${attempt} times: [${resp}]`
);
}

const delay = baseTimeout * attempt;
const delay = attempt * 2000;
this.log.debug(`Github responded with ${status}, retrying in ${delay} ms: [${resp}]`);
await new Promise((resolve) => setTimeout(resolve, delay));
continue;
Expand Down

0 comments on commit 927bab6

Please sign in to comment.