(path: string, init?: RequestInit)
| 70 | } |
| 71 | |
| 72 | async function apiRequest<T>(path: string, init?: RequestInit): Promise<T> { |
| 73 | const authHeaders = await getAuthHeader(); |
| 74 | const { headers: initHeaders, ...restInit } = init ?? {}; |
| 75 | const response = await fetch(`${API_BASE}${path}`, { |
| 76 | cache: "no-store", |
| 77 | ...restInit, |
| 78 | headers: { |
| 79 | Accept: "application/json", |
| 80 | ...authHeaders, |
| 81 | ...(initHeaders as Record<string, string> | undefined), |
| 82 | }, |
| 83 | }); |
| 84 | |
| 85 | if (!response.ok) { |
| 86 | throw await toApiError(response, path); |
| 87 | } |
| 88 | |
| 89 | if ( |
| 90 | response.status === 204 || |
| 91 | response.headers.get("content-length") === "0" |
| 92 | ) { |
| 93 | return undefined as T; |
| 94 | } |
| 95 | |
| 96 | return (await response.json()) as T; |
| 97 | } |
| 98 | |
| 99 | async function apiBlobRequest(path: string): Promise<{ |
| 100 | blob: Blob; |
no test coverage detected
searching dependent graphs…