From 7ae9006dd46e9f39ed0f32f6e4668d7e566ee17e Mon Sep 17 00:00:00 2001 From: "Jacob Hands [CF]" Date: Mon, 3 Jul 2023 13:55:34 -0500 Subject: [PATCH] fix: do not retry status code 451 by default (#447) 451 is returned when a resource has been restricted for legal reasons. Retrying this status needlessly wastes API quota --- README.md | 2 +- src/index.ts | 2 +- test/retry.test.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d1abca54..2c3a5192 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # plugin-retry.js -> Retries requests for server 4xx/5xx responses except `400`, `401`, `403`, `404`, and `422`. +> Retries requests for server 4xx/5xx responses except `400`, `401`, `403`, `404`, `422`, and `451`. [![@latest](https://img.shields.io/npm/v/@octokit/plugin-retry.svg)](https://www.npmjs.com/package/@octokit/plugin-retry) [![Build Status](https://github.com/octokit/plugin-retry.js/workflows/Test/badge.svg)](https://github.com/octokit/plugin-retry.js/actions?workflow=Test) diff --git a/src/index.ts b/src/index.ts index eae8e01e..d1b96cf2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,7 +11,7 @@ export function retry(octokit: Octokit, octokitOptions: any) { { enabled: true, retryAfterBaseValue: 1000, - doNotRetry: [400, 401, 403, 404, 422], + doNotRetry: [400, 401, 403, 404, 422, 451], retries: 3, }, octokitOptions.retry diff --git a/test/retry.test.ts b/test/retry.test.ts index 8365de75..eb94af94 100644 --- a/test/retry.test.ts +++ b/test/retry.test.ts @@ -205,10 +205,10 @@ describe("Automatic Retries", function () { expect(ms2).toBeGreaterThan(420); }); - it("Should not retry 3xx/400/401/403/422 errors", async function () { + it("Should not retry 3xx/400/401/403/422/451 errors", async function () { const octokit = new TestOctokit({ retry: { retryAfterBaseValue: 50 } }); let caught = 0; - const testStatuses = [304, 400, 401, 403, 404, 422]; + const testStatuses = [304, 400, 401, 403, 404, 422, 451]; for (const status of testStatuses) { try { @@ -241,7 +241,7 @@ describe("Automatic Retries", function () { }, }); let caught = 0; - const testStatuses = [304, 400, 401, 403, 404]; + const testStatuses = [304, 400, 401, 403, 404, 422, 451]; for (const status of testStatuses) { try {