not found reasons + json parsing

This commit is contained in:
mrjvs
2023-09-06 17:40:03 +02:00
parent d325dab162
commit ee2b63034e
4 changed files with 11 additions and 5 deletions

View File

@@ -5,12 +5,11 @@ import { makeFullUrl } from '@/fetchers/common';
import { Fetcher } from '@/fetchers/types';
export function makeStandardFetcher(f: typeof fetch): Fetcher {
const normalFetch: Fetcher = (url, ops) => {
const normalFetch: Fetcher = async (url, ops) => {
const fullUrl = makeFullUrl(url, ops);
const seralizedBody = serializeBody(ops.body);
return f(fullUrl, {
const res = await f(fullUrl, {
method: ops.method,
headers: {
...seralizedBody.headers,
@@ -18,6 +17,10 @@ export function makeStandardFetcher(f: typeof fetch): Fetcher {
},
body: seralizedBody.body,
});
const isJson = res.headers.get('content-type')?.includes('application/json');
if (isJson) return res.json();
return res.text();
};
return normalFetch;