@kevisual/query 0.0.7-alpha.3 → 0.0.7
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/query-browser.d.ts +1 -2
- package/dist/query-browser.js +30 -8
- package/dist/query.js +26 -6
- package/package.json +1 -1
package/dist/query-browser.d.ts
CHANGED
|
@@ -120,6 +120,5 @@ declare class QueryClient<U = any, V = any> extends Query<U, V> {
|
|
|
120
120
|
saveToken(token: string): void;
|
|
121
121
|
removeToken(): void;
|
|
122
122
|
}
|
|
123
|
-
declare const client: QueryClient<any, any>;
|
|
124
123
|
|
|
125
|
-
export { Query, QueryClient, type QueryOpts, QueryWs, type QueryWsOpts, adapter
|
|
124
|
+
export { Query, QueryClient, type QueryOpts, QueryWs, type QueryWsOpts, adapter };
|
package/dist/query-browser.js
CHANGED
|
@@ -262,15 +262,35 @@ class Query {
|
|
|
262
262
|
body,
|
|
263
263
|
timeout,
|
|
264
264
|
};
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
try {
|
|
266
|
+
if (beforeRequest) {
|
|
267
|
+
await beforeRequest(req);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
catch (e) {
|
|
271
|
+
console.error(e);
|
|
272
|
+
return {
|
|
273
|
+
code: 500,
|
|
274
|
+
success: false,
|
|
275
|
+
message: 'api request beforeFn error',
|
|
276
|
+
};
|
|
267
277
|
}
|
|
268
278
|
return adapter(req).then(async (res) => {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
279
|
+
try {
|
|
280
|
+
res.success = res.code === 200;
|
|
281
|
+
if (afterResponse) {
|
|
282
|
+
return await afterResponse(res);
|
|
283
|
+
}
|
|
284
|
+
return res;
|
|
285
|
+
}
|
|
286
|
+
catch (e) {
|
|
287
|
+
console.error(e);
|
|
288
|
+
return {
|
|
289
|
+
code: 500,
|
|
290
|
+
success: false,
|
|
291
|
+
message: 'api request afterFn error',
|
|
292
|
+
};
|
|
272
293
|
}
|
|
273
|
-
return res;
|
|
274
294
|
});
|
|
275
295
|
}
|
|
276
296
|
before(fn) {
|
|
@@ -288,6 +308,7 @@ class QueryClient extends Query {
|
|
|
288
308
|
tokenName;
|
|
289
309
|
storage;
|
|
290
310
|
token;
|
|
311
|
+
// 默认不使用ws
|
|
291
312
|
qws;
|
|
292
313
|
constructor(opts) {
|
|
293
314
|
super(opts);
|
|
@@ -320,6 +341,7 @@ class QueryClient extends Query {
|
|
|
320
341
|
this.storage.removeItem(this.tokenName);
|
|
321
342
|
}
|
|
322
343
|
}
|
|
323
|
-
|
|
344
|
+
// 移除默认生成的实例
|
|
345
|
+
// export const client = new QueryClient();
|
|
324
346
|
|
|
325
|
-
export { Query, QueryClient, QueryWs, adapter
|
|
347
|
+
export { Query, QueryClient, QueryWs, adapter };
|
package/dist/query.js
CHANGED
|
@@ -79,15 +79,35 @@ class Query {
|
|
|
79
79
|
body,
|
|
80
80
|
timeout,
|
|
81
81
|
};
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
try {
|
|
83
|
+
if (beforeRequest) {
|
|
84
|
+
await beforeRequest(req);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
console.error(e);
|
|
89
|
+
return {
|
|
90
|
+
code: 500,
|
|
91
|
+
success: false,
|
|
92
|
+
message: 'api request beforeFn error',
|
|
93
|
+
};
|
|
84
94
|
}
|
|
85
95
|
return adapter(req).then(async (res) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
96
|
+
try {
|
|
97
|
+
res.success = res.code === 200;
|
|
98
|
+
if (afterResponse) {
|
|
99
|
+
return await afterResponse(res);
|
|
100
|
+
}
|
|
101
|
+
return res;
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
console.error(e);
|
|
105
|
+
return {
|
|
106
|
+
code: 500,
|
|
107
|
+
success: false,
|
|
108
|
+
message: 'api request afterFn error',
|
|
109
|
+
};
|
|
89
110
|
}
|
|
90
|
-
return res;
|
|
91
111
|
});
|
|
92
112
|
}
|
|
93
113
|
before(fn) {
|