(
path: string,
options: RequestInit = {}
)
| 29 | |
| 30 | /** Wrapper around fetch with credentials and common headers. */ |
| 31 | export async function apiFetch( |
| 32 | path: string, |
| 33 | options: RequestInit = {} |
| 34 | ): Promise<Response> { |
| 35 | const headers = new Headers(options.headers); |
| 36 | const isFormData = options.body instanceof FormData; |
| 37 | if (!isFormData && !headers.has('Content-Type')) { |
| 38 | headers.set('Content-Type', 'application/json'); |
| 39 | } |
| 40 | |
| 41 | const response = await fetch(path, { |
| 42 | ...options, |
| 43 | headers, |
| 44 | credentials: 'include', // Send cookies with every request |
| 45 | }); |
| 46 | |
| 47 | await handleUnauthorized(response); |
| 48 | |
| 49 | return response; |
| 50 | } |
| 51 | |
| 52 | function headersFromXhr(rawHeaders: string): Headers { |
| 53 | const headers = new Headers(); |
no test coverage detected