mirror of
https://github.com/movie-web/providers.git
synced 2025-09-13 17:43:25 +00:00
not found reasons + json parsing
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user