Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 4x 4x 1x 3x 3x 2x 1x 1x | function api<T>(url: string, options?: RequestInit): Promise<T> { return fetch(url, options).then((response) => { if (!response.ok) { throw new Error(response.statusText); } const contentType = response.headers.get("Content-Type"); if (/application\/json/.test(contentType)) { return response.json() as Promise<T>; } return (response.text() as any) as Promise<T>; }); } export default api; |