Skip to content

Commit 07a1e8d

Browse files
fix(js-api-client): remove try/catch
1 parent b83d525 commit 07a1e8d

File tree

1 file changed

+60
-80
lines changed

1 file changed

+60
-80
lines changed

src/core/editCart.ts

Lines changed: 60 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,17 @@ type Deps = {
77
};
88

99
export const placeCart = async (cartId: string, { apiClient }: Deps, extraQuery?: any): Promise<void> => {
10-
try {
11-
const mutation = {
12-
place: {
13-
__args: {
14-
id: cartId,
15-
},
16-
id: true,
17-
...extraQuery,
10+
const mutation = {
11+
place: {
12+
__args: {
13+
id: cartId,
1814
},
19-
};
20-
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
21-
return response.place;
22-
} catch (exception: any) {
23-
console.error(`Failed to place cart ${cartId}`, exception.message);
24-
}
15+
id: true,
16+
...extraQuery,
17+
},
18+
};
19+
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
20+
return response.place;
2521
};
2622

2723
export const addSkuItem = async (
@@ -31,25 +27,21 @@ export const addSkuItem = async (
3127
{ apiClient }: Deps,
3228
extraQuery?: any,
3329
) => {
34-
try {
35-
const mutation = {
36-
addSkuItem: {
37-
__args: {
38-
id: cartId,
39-
input: {
40-
sku,
41-
quantity,
42-
},
30+
const mutation = {
31+
addSkuItem: {
32+
__args: {
33+
id: cartId,
34+
input: {
35+
sku,
36+
quantity,
4337
},
44-
id: true,
45-
...extraQuery,
4638
},
47-
};
48-
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
49-
return response.addSkuItem;
50-
} catch (exception: any) {
51-
console.error(`Failed to add sku item for cart ${cartId}`, exception.message);
52-
}
39+
id: true,
40+
...extraQuery,
41+
},
42+
};
43+
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
44+
return response.addSkuItem;
5345
};
5446

5547
export const removeCartItem = async (
@@ -59,23 +51,19 @@ export const removeCartItem = async (
5951
{ apiClient }: Deps,
6052
extraQuery?: any,
6153
) => {
62-
try {
63-
const mutation = {
64-
removeCartItem: {
65-
__args: {
66-
id: cartId,
67-
sku,
68-
quantity,
69-
},
70-
id: true,
71-
...extraQuery,
54+
const mutation = {
55+
removeCartItem: {
56+
__args: {
57+
id: cartId,
58+
sku,
59+
quantity,
7260
},
73-
};
74-
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
75-
return response.removeCartItem;
76-
} catch (exception: any) {
77-
console.error(`Failed to remove from cart ${cartId}`, exception.message);
78-
}
61+
id: true,
62+
...extraQuery,
63+
},
64+
};
65+
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
66+
return response.removeCartItem;
7967
};
8068

8169
export const setCartMeta = async (
@@ -88,23 +76,19 @@ export const setCartMeta = async (
8876
{ apiClient }: Deps,
8977
extraQuery?: any,
9078
): Promise<void> => {
91-
try {
92-
const mutation = {
93-
setMeta: {
94-
__args: {
95-
id: cartId,
96-
merge,
97-
meta,
98-
},
99-
id: true,
100-
...extraQuery,
79+
const mutation = {
80+
setMeta: {
81+
__args: {
82+
id: cartId,
83+
merge,
84+
meta,
10185
},
102-
};
103-
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
104-
return response.setMeta;
105-
} catch (exception: any) {
106-
console.error(`Failed to set meta for ${cartId}`, exception.message);
107-
}
86+
id: true,
87+
...extraQuery,
88+
},
89+
};
90+
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
91+
return response.setMeta;
10892
};
10993

11094
export const setCartCustomer = async (
@@ -114,23 +98,19 @@ export const setCartCustomer = async (
11498
{ apiClient }: Deps,
11599
extraQuery?: any,
116100
): Promise<void> => {
117-
try {
118-
const mutation = {
119-
setCustomer: {
120-
__args: {
121-
id: cartId,
122-
input: {
123-
isGuest,
124-
...customer,
125-
},
101+
const mutation = {
102+
setCustomer: {
103+
__args: {
104+
id: cartId,
105+
input: {
106+
isGuest,
107+
...customer,
126108
},
127-
id: true,
128-
...extraQuery,
129109
},
130-
};
131-
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
132-
return response.setCustomer;
133-
} catch (exception: any) {
134-
console.error('Failed to update customer', exception.message);
135-
}
110+
id: true,
111+
...extraQuery,
112+
},
113+
};
114+
const response = await apiClient.shopCartApi(jsonToGraphQLQuery({ mutation }));
115+
return response.setCustomer;
136116
};

0 commit comments

Comments
 (0)