xxf_react 0.8.8 → 0.9.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PromiseExt.d.ts","sourceRoot":"","sources":["../../src/flow/PromiseExt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PromiseExt.d.ts","sourceRoot":"","sources":["../../src/flow/PromiseExt.ts"],"names":[],"mappings":"AAKA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,OAAO,CAAC,CAAC;QACf,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;KACjE;CACJ;AAGD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAM1D;AAGD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE3D;AAED,wBAAgB,yBAAyB,IAAI,IAAI,CAkDhD"}
|
package/dist/flow/PromiseExt.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
// src/lib/promise_ext.ts
|
|
2
2
|
import { toast } from "react-toastify";
|
|
3
|
+
import { ApiError } from "../models/ApiResponse";
|
|
3
4
|
// 或者更完整的判断
|
|
4
5
|
export function isSafariLoadFailed(error) {
|
|
5
6
|
return (error instanceof TypeError &&
|
|
6
7
|
(error.message === 'Load failed' ||
|
|
7
8
|
error.message.includes('Load failed')));
|
|
8
9
|
}
|
|
10
|
+
// 判断是否为 401 未授权错误
|
|
11
|
+
export function isUnauthorizedError(error) {
|
|
12
|
+
return error instanceof ApiError && error.code === 401;
|
|
13
|
+
}
|
|
9
14
|
export function initPromiseErrorExtension() {
|
|
10
15
|
if (typeof Promise === 'undefined') {
|
|
11
16
|
console.warn('Promise is not available in this environment.');
|
|
@@ -20,7 +25,9 @@ export function initPromiseErrorExtension() {
|
|
|
20
25
|
Object.defineProperty(Promise.prototype, 'bindErrorNotice', {
|
|
21
26
|
value: function (filter) {
|
|
22
27
|
return this.catch((error) => {
|
|
23
|
-
const shouldHandle = filter
|
|
28
|
+
const shouldHandle = filter
|
|
29
|
+
? filter(error)
|
|
30
|
+
: !isSafariLoadFailed(error) && !isUnauthorizedError(error);
|
|
24
31
|
if (shouldHandle) {
|
|
25
32
|
// 错误处理逻辑
|
|
26
33
|
console.error('==========>[Promise Error Notice]', {
|
|
@@ -53,8 +53,8 @@ export class HttpClient {
|
|
|
53
53
|
headers: {},
|
|
54
54
|
timeout: 30000,
|
|
55
55
|
retry: 2,
|
|
56
|
-
memoryCacheMaxSize:
|
|
57
|
-
diskCacheMaxSize:
|
|
56
|
+
memoryCacheMaxSize: 500,
|
|
57
|
+
diskCacheMaxSize: 5000,
|
|
58
58
|
dbName: 'xxf-http-cache',
|
|
59
59
|
defaultKeyHeaders: [], // 默认不包含任何 header,避免 token 变化导致缓存失效
|
|
60
60
|
defaultCache: undefined, // 默认不缓存 (OnlyRemote)
|
|
@@ -31,9 +31,9 @@ export interface HttpClientConfig {
|
|
|
31
31
|
timeout?: number;
|
|
32
32
|
/** 默认重试次数,默认 2 */
|
|
33
33
|
retry?: number;
|
|
34
|
-
/** 内存缓存最大条目数,默认
|
|
34
|
+
/** 内存缓存最大条目数,默认 500 */
|
|
35
35
|
memoryCacheMaxSize?: number;
|
|
36
|
-
/** 磁盘缓存最大条目数,默认
|
|
36
|
+
/** 磁盘缓存最大条目数,默认 5000 */
|
|
37
37
|
diskCacheMaxSize?: number;
|
|
38
38
|
/** IndexedDB 数据库名,默认 'xxf-http-cache' */
|
|
39
39
|
dbName?: string;
|