( url: string, requestInitWithoutMethod?: Omit<RequestInit, "method">, retryCount = 0 )
| 951 | } |
| 952 | |
| 953 | async function fetchHead( |
| 954 | url: string, |
| 955 | requestInitWithoutMethod?: Omit<RequestInit, "method">, |
| 956 | retryCount = 0 |
| 957 | ): Promise<Response> { |
| 958 | const requestInit: RequestInit = { |
| 959 | ...requestInitWithoutMethod, |
| 960 | method: "HEAD", |
| 961 | }; |
| 962 | const response = await fetch(url, requestInitWithCache(requestInit)); |
| 963 | |
| 964 | if (response.status >= 500 && retryCount < MAX_RETRIES) { |
| 965 | // retry with exponential backoff and jitter |
| 966 | const delay = exponentialBackoff(retryCount + 1); |
| 967 | |
| 968 | await new Promise((resolve) => setTimeout(resolve, delay)); |
| 969 | |
| 970 | return fetchHead(url, requestInitWithoutMethod, retryCount + 1); |
| 971 | } |
| 972 | |
| 973 | return response; |
| 974 | } |
| 975 | |
| 976 | async function zodfetch<TResponseSchema extends z.ZodTypeAny, TOptional extends boolean = false>( |
| 977 | schema: TResponseSchema, |
no test coverage detected
searching dependent graphs…