From ecfdf9ce281970a1c1e494531ab6bb744962acd5 Mon Sep 17 00:00:00 2001 From: Jacob Hands Date: Mon, 3 Jul 2023 12:40:56 -0500 Subject: [PATCH] fix: Do not retry status code 451 by default 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 {