(path, {allowUnauthorized = false, body, contentType, fetchPriority, headers, ...options} = {})
| 8 | } |
| 9 | |
| 10 | export async function apiRequest(path, {allowUnauthorized = false, body, contentType, fetchPriority, headers, ...options} = {}) { |
| 11 | const response = await fetch(path, { |
| 12 | method: 'POST', |
| 13 | credentials: 'include', |
| 14 | headers: { |
| 15 | ...createHeaders(contentType), |
| 16 | ...headers, |
| 17 | }, |
| 18 | ...options, |
| 19 | ...(fetchPriority ? {priority: fetchPriority} : {}), |
| 20 | ...(body === undefined |
| 21 | ? {} |
| 22 | : {body: typeof body === 'string' ? body : JSON.stringify(body)}), |
| 23 | }); |
| 24 | await handleErrors(response, {allowUnauthorized}); |
| 25 | return response; |
| 26 | } |
| 27 | |
| 28 | export async function apiJson(path, options) { |
| 29 | return (await apiRequest(path, options)).json(); |
no test coverage detected