Update fetch rest

This commit is contained in:
goncy
2021-09-30 15:50:30 -03:00
parent 4ab3cf5214
commit 19a5e22302

View File

@@ -1,4 +1,3 @@
import Cookies from 'js-cookie'
import vercelFetch from '@vercel/fetch' import vercelFetch from '@vercel/fetch'
import { FetcherError } from '@commerce/utils/errors' import { FetcherError } from '@commerce/utils/errors'
@@ -86,13 +85,7 @@ export async function fetchData<T>(opts: {
try { try {
// Return data response as json // Return data response as json
const data = (await dataResponse.json()) as Promise<T> return (await dataResponse.json()) as Promise<T>
// Return data with meta
return {
meta: { token },
...data,
}
} catch (error) { } catch (error) {
// If response is empty return it as text // If response is empty return it as text
return null as unknown as Promise<T> return null as unknown as Promise<T>
@@ -167,7 +160,7 @@ export const createBuyerFetcher: (
} }
// Return the data and specify the expected type // Return the data and specify the expected type
return fetchData<T>({ const data = await fetchData<T>({
token: global.token as string, token: global.token as string,
fetchOptions, fetchOptions,
config, config,
@@ -175,4 +168,9 @@ export const createBuyerFetcher: (
path, path,
body, body,
}) })
return {
...data,
meta: { token: global.token as string },
}
} }