fix: retry HTTP fetch on 408, 409, 420, 429 status codes from the server (#4005)

This commit is contained in:
Zoltan Kochan
2021-11-17 22:31:38 +02:00
committed by GitHub
parent d42f991f47
commit 12ee3c144e
2 changed files with 8 additions and 1 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/fetch": patch
"pnpm": patch
---
HTTP requests should be retried when the server responds with on of 408, 409, 420, 429 status codes.

View File

@@ -34,7 +34,8 @@ export default async function fetchRetry (url: RequestInfo, opts: RequestInit =
try {
// this will be retried
const res = await fetch(url as any, opts) // eslint-disable-line
if ((res.status >= 500 && res.status < 600) || res.status === 429) {
// A retry on 409 sometimes helps when making requests to the Bit registry.
if ((res.status >= 500 && res.status < 600) || [408, 409, 420, 429].includes(res.status)) {
throw new ResponseError(res)
} else {
resolve(res)