@longvansoftware/storefront-js-client 1.7.8 → 1.7.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -10,6 +10,7 @@ export declare class Service {
|
|
|
10
10
|
setToken(token: string): void;
|
|
11
11
|
setStoreId(storeId: string): void;
|
|
12
12
|
setOrgId(orgId: string): void;
|
|
13
|
+
private handleApolloError;
|
|
13
14
|
protected graphqlQuery(query: DocumentNode, variables: any): Promise<any>;
|
|
14
15
|
protected graphqlMutation(mutation: DocumentNode, variables: any): Promise<any>;
|
|
15
16
|
protected restApiCallWithToken(path: string, method: "GET" | "POST" | "PUT" | "DELETE", data?: any, headers?: any): Promise<any>;
|
|
@@ -43,6 +43,16 @@ class Service {
|
|
|
43
43
|
setOrgId(orgId) {
|
|
44
44
|
this.orgId = orgId;
|
|
45
45
|
}
|
|
46
|
+
// Hàm xử lý lỗi từ Apollo Client
|
|
47
|
+
handleApolloError(error) {
|
|
48
|
+
if (error.graphQLErrors && error.graphQLErrors.length > 0) {
|
|
49
|
+
return error.graphQLErrors.map((err) => err.message).join(", ");
|
|
50
|
+
}
|
|
51
|
+
if (error.networkError) {
|
|
52
|
+
return `Network Error: ${error.networkError.message}`;
|
|
53
|
+
}
|
|
54
|
+
return error.message || "An unknown error occurred";
|
|
55
|
+
}
|
|
46
56
|
graphqlQuery(query, variables) {
|
|
47
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
58
|
try {
|
|
@@ -59,14 +69,14 @@ class Service {
|
|
|
59
69
|
},
|
|
60
70
|
},
|
|
61
71
|
});
|
|
62
|
-
if (errors) {
|
|
63
|
-
throw
|
|
72
|
+
if (errors && errors.length > 0) {
|
|
73
|
+
throw this.handleApolloError({ graphQLErrors: errors });
|
|
64
74
|
}
|
|
65
75
|
return data;
|
|
66
76
|
}
|
|
67
77
|
catch (error) {
|
|
68
|
-
|
|
69
|
-
throw
|
|
78
|
+
const errorMessage = this.handleApolloError(error);
|
|
79
|
+
throw errorMessage; // Throw message trực tiếp
|
|
70
80
|
}
|
|
71
81
|
});
|
|
72
82
|
}
|
|
@@ -86,13 +96,14 @@ class Service {
|
|
|
86
96
|
},
|
|
87
97
|
},
|
|
88
98
|
});
|
|
89
|
-
if (errors) {
|
|
90
|
-
throw
|
|
99
|
+
if (errors && errors.length > 0) {
|
|
100
|
+
throw this.handleApolloError({ graphQLErrors: errors });
|
|
91
101
|
}
|
|
92
102
|
return data;
|
|
93
103
|
}
|
|
94
104
|
catch (error) {
|
|
95
|
-
|
|
105
|
+
const errorMessage = this.handleApolloError(error);
|
|
106
|
+
throw errorMessage; // Throw message trực tiếp
|
|
96
107
|
}
|
|
97
108
|
});
|
|
98
109
|
}
|