|
|
@@ -141,6 +141,7 @@ export async function bagistoFetch<T>({
|
|
|
isCookies = true,
|
|
|
guestToken,
|
|
|
revalidate = 60,
|
|
|
+ operationName = ''
|
|
|
}: {
|
|
|
cache?: RequestCache;
|
|
|
headers?: HeadersInit | Record<string, string>;
|
|
|
@@ -150,6 +151,7 @@ export async function bagistoFetch<T>({
|
|
|
isCookies?: boolean;
|
|
|
guestToken?: string;
|
|
|
revalidate?: number;
|
|
|
+ operationName?: string;
|
|
|
}): Promise<{ status: number; body: T } | never> {
|
|
|
try {
|
|
|
const queryString =
|
|
|
@@ -189,7 +191,12 @@ export async function bagistoFetch<T>({
|
|
|
Object.assign(baseHeaders, headers);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ // let cc = await cookies();
|
|
|
+ // console.log('bagistoFetch --- url:', GRAPHQL_URL,isCookies);
|
|
|
+ // console.log('bagistoFetch --- queryString:', queryString);
|
|
|
+ // console.log('bagistoFetch --- baseHeaders:', baseHeaders);
|
|
|
+ // console.log('bagistoFetch --- cookies:', cc.getAll());
|
|
|
+ // console.log('bagistoFetch --- variables:', variables);
|
|
|
const result = await fetch(GRAPHQL_URL, {
|
|
|
method: "POST",
|
|
|
headers: baseHeaders,
|
|
|
@@ -205,9 +212,13 @@ export async function bagistoFetch<T>({
|
|
|
});
|
|
|
|
|
|
const body = await result.json();
|
|
|
-
|
|
|
- if (body.errors) throw body.errors[0];
|
|
|
-
|
|
|
+ // console.log('bagistoFetch --- body:',body);
|
|
|
+ if (body.errors) {
|
|
|
+ if(operationName === 'GetCartItem' && body.errors[0].message === 'Cart not found') {
|
|
|
+ return { status: result.status, body };
|
|
|
+ }
|
|
|
+ throw body.errors[0]
|
|
|
+ }
|
|
|
return { status: result.status, body };
|
|
|
} catch (e) {
|
|
|
throw e;
|