Skip to content

Commit

Permalink
fix(js-api-client): remove try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
dhairyadwivedi committed May 20, 2024
1 parent b83d525 commit 07a1e8d
Showing 1 changed file with 60 additions and 80 deletions.
140 changes: 60 additions & 80 deletions src/core/editCart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ type Deps = {
};

export const placeCart = async (cartId: string, { apiClient }: Deps, extraQuery?: any): Promise<void> => {
try {
const mutation = {
place: {
__args: {
id: cartId,
},
id: true,
...extraQuery,
const mutation = {
place: {
__args: {
id: cartId,
},
};
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
return response.place;
} catch (exception: any) {
console.error(`Failed to place cart ${cartId}`, exception.message);
}
id: true,
...extraQuery,
},
};
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
return response.place;
};

export const addSkuItem = async (
Expand All @@ -31,25 +27,21 @@ export const addSkuItem = async (
{ apiClient }: Deps,
extraQuery?: any,
) => {
try {
const mutation = {
addSkuItem: {
__args: {
id: cartId,
input: {
sku,
quantity,
},
const mutation = {
addSkuItem: {
__args: {
id: cartId,
input: {
sku,
quantity,
},
id: true,
...extraQuery,
},
};
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
return response.addSkuItem;
} catch (exception: any) {
console.error(`Failed to add sku item for cart ${cartId}`, exception.message);
}
id: true,
...extraQuery,
},
};
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
return response.addSkuItem;
};

export const removeCartItem = async (
Expand All @@ -59,23 +51,19 @@ export const removeCartItem = async (
{ apiClient }: Deps,
extraQuery?: any,
) => {
try {
const mutation = {
removeCartItem: {
__args: {
id: cartId,
sku,
quantity,
},
id: true,
...extraQuery,
const mutation = {
removeCartItem: {
__args: {
id: cartId,
sku,
quantity,
},
};
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
return response.removeCartItem;
} catch (exception: any) {
console.error(`Failed to remove from cart ${cartId}`, exception.message);
}
id: true,
...extraQuery,
},
};
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
return response.removeCartItem;
};

export const setCartMeta = async (
Expand All @@ -88,23 +76,19 @@ export const setCartMeta = async (
{ apiClient }: Deps,
extraQuery?: any,
): Promise<void> => {
try {
const mutation = {
setMeta: {
__args: {
id: cartId,
merge,
meta,
},
id: true,
...extraQuery,
const mutation = {
setMeta: {
__args: {
id: cartId,
merge,
meta,
},
};
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
return response.setMeta;
} catch (exception: any) {
console.error(`Failed to set meta for ${cartId}`, exception.message);
}
id: true,
...extraQuery,
},
};
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
return response.setMeta;
};

export const setCartCustomer = async (
Expand All @@ -114,23 +98,19 @@ export const setCartCustomer = async (
{ apiClient }: Deps,
extraQuery?: any,
): Promise<void> => {
try {
const mutation = {
setCustomer: {
__args: {
id: cartId,
input: {
isGuest,
...customer,
},
const mutation = {
setCustomer: {
__args: {
id: cartId,
input: {
isGuest,
...customer,
},
id: true,
...extraQuery,
},
};
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
return response.setCustomer;
} catch (exception: any) {
console.error('Failed to update customer', exception.message);
}
id: true,
...extraQuery,
},
};
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
return response.setCustomer;
};

0 comments on commit 07a1e8d

Please sign in to comment.