Wrapped logic to perform HTTP requests with fetch into an HttpClient class

This commit is contained in:
Alejandro Celaya
2022-11-15 20:31:35 +01:00
parent a0767417b3
commit 9b3bdebb28
13 changed files with 142 additions and 115 deletions

View File

@@ -1,10 +0,0 @@
export const jsonFetch = (fetch: typeof window.fetch) => <T>(url: string, options?: RequestInit) => fetch(url, options)
.then(async (resp) => {
const parsed = await resp.json();
if (!resp.ok) {
throw parsed; // eslint-disable-line @typescript-eslint/no-throw-literal
}
return parsed as T;
});