@waywake/youzanyun-sdk 2.0.1 → 2.0.2
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.
package/dist/cjs/index.js
CHANGED
|
@@ -109,6 +109,17 @@ class HttpError extends Error {
|
|
|
109
109
|
this.response = response;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
+
|
|
113
|
+
class YouzanApiError extends Error {
|
|
114
|
+
response;
|
|
115
|
+
constructor(response) {
|
|
116
|
+
const data = response.data;
|
|
117
|
+
const message = typeof data.message === "string" ? data.message : "Youzan API request failed";
|
|
118
|
+
super(message);
|
|
119
|
+
this.name = "YouzanApiError";
|
|
120
|
+
this.response = response;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
112
123
|
function getRequestUrl(url) {
|
|
113
124
|
return new URL(url, getBaseUrl()).toString();
|
|
114
125
|
}
|
|
@@ -141,8 +152,14 @@ async function toHttpResponse(resp) {
|
|
|
141
152
|
if (!resp.ok) {
|
|
142
153
|
throw new HttpError(response);
|
|
143
154
|
}
|
|
155
|
+
if (isFailedApiResponse(response.data)) {
|
|
156
|
+
throw new YouzanApiError(response);
|
|
157
|
+
}
|
|
144
158
|
return response;
|
|
145
159
|
}
|
|
160
|
+
function isFailedApiResponse(data) {
|
|
161
|
+
return typeof data === "object" && data !== null && "success" in data && data.success === false;
|
|
162
|
+
}
|
|
146
163
|
async function post(url, params) {
|
|
147
164
|
const resp = await fetch(getRequestUrl(url), {
|
|
148
165
|
method: "POST",
|
package/dist/cjs/utils/http.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ export declare class HttpError<T = unknown> extends Error {
|
|
|
12
12
|
response: HttpResponse<T>;
|
|
13
13
|
constructor(response: HttpResponse<T>);
|
|
14
14
|
}
|
|
15
|
+
export declare class YouzanApiError<T = unknown> extends Error {
|
|
16
|
+
response: HttpResponse<T>;
|
|
17
|
+
constructor(response: HttpResponse<T>);
|
|
18
|
+
}
|
|
15
19
|
/**
|
|
16
20
|
* 发起 POST 请求
|
|
17
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/utils/http.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,qBAAa,SAAS,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,KAAK;IAC/C,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;gBAEd,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;CAKtC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/utils/http.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,qBAAa,SAAS,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,KAAK;IAC/C,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;gBAEd,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;CAKtC;AAED,qBAAa,cAAc,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,KAAK;IACpD,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;gBAEd,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;CAQtC;AAoDD;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,kCAUvE;AAED;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,kCAiB5F"}
|
package/dist/esm/index.js
CHANGED
|
@@ -50,6 +50,17 @@ class HttpError extends Error {
|
|
|
50
50
|
this.response = response;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
+
|
|
54
|
+
class YouzanApiError extends Error {
|
|
55
|
+
response;
|
|
56
|
+
constructor(response) {
|
|
57
|
+
const data = response.data;
|
|
58
|
+
const message = typeof data.message === "string" ? data.message : "Youzan API request failed";
|
|
59
|
+
super(message);
|
|
60
|
+
this.name = "YouzanApiError";
|
|
61
|
+
this.response = response;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
53
64
|
function getRequestUrl(url) {
|
|
54
65
|
return new URL(url, getBaseUrl()).toString();
|
|
55
66
|
}
|
|
@@ -82,8 +93,14 @@ async function toHttpResponse(resp) {
|
|
|
82
93
|
if (!resp.ok) {
|
|
83
94
|
throw new HttpError(response);
|
|
84
95
|
}
|
|
96
|
+
if (isFailedApiResponse(response.data)) {
|
|
97
|
+
throw new YouzanApiError(response);
|
|
98
|
+
}
|
|
85
99
|
return response;
|
|
86
100
|
}
|
|
101
|
+
function isFailedApiResponse(data) {
|
|
102
|
+
return typeof data === "object" && data !== null && "success" in data && data.success === false;
|
|
103
|
+
}
|
|
87
104
|
async function post(url, params) {
|
|
88
105
|
const resp = await fetch(getRequestUrl(url), {
|
|
89
106
|
method: "POST",
|
package/dist/esm/utils/http.d.ts
CHANGED
|
@@ -12,6 +12,10 @@ export declare class HttpError<T = unknown> extends Error {
|
|
|
12
12
|
response: HttpResponse<T>;
|
|
13
13
|
constructor(response: HttpResponse<T>);
|
|
14
14
|
}
|
|
15
|
+
export declare class YouzanApiError<T = unknown> extends Error {
|
|
16
|
+
response: HttpResponse<T>;
|
|
17
|
+
constructor(response: HttpResponse<T>);
|
|
18
|
+
}
|
|
15
19
|
/**
|
|
16
20
|
* 发起 POST 请求
|
|
17
21
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/utils/http.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,qBAAa,SAAS,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,KAAK;IAC/C,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;gBAEd,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;CAKtC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/utils/http.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,qBAAa,SAAS,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,KAAK;IAC/C,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;gBAEd,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;CAKtC;AAED,qBAAa,cAAc,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,KAAK;IACpD,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;gBAEd,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;CAQtC;AAoDD;;;;;GAKG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,kCAUvE;AAED;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,kCAiB5F"}
|