mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Update fetch rest
This commit is contained in:
@@ -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 },
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user