(url: string, opts: FetchOptions = {})
| 59 | }; |
| 60 | |
| 61 | export function fetchWithRetry(url: string, opts: FetchOptions = {}) { |
| 62 | return retry( |
| 63 | async () => { |
| 64 | const res = await nodeFetch(url, opts); |
| 65 | |
| 66 | if (res.status !== opts.status) { |
| 67 | const text = await res.text(); |
| 68 | throw new Error( |
| 69 | `Failed to fetch "${url}", received ${res.status}, expected ${ |
| 70 | opts.status |
| 71 | }, id: ${res.headers.get('x-vercel-id')}:\n\n${text}\n\n` |
| 72 | ); |
| 73 | } |
| 74 | |
| 75 | return res; |
| 76 | }, |
| 77 | { |
| 78 | retries: opts.retries ?? 3, |
| 79 | factor: 1, |
| 80 | } |
| 81 | ); |
| 82 | } |
| 83 | |
| 84 | type ResolverPromise<T> = Promise<T> & { |
| 85 | resolve: (value: PromiseLike<null> | null) => void; |
no test coverage detected