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.
@@ -39,8 +39,8 @@ export interface DiskLruCacheConfig {
39
39
  * @example
40
40
  * ```ts
41
41
  * const cache = new HttpCache({
42
- * memoryMaxSize: 100,
43
- * diskMaxSize: 500,
42
+ * memoryMaxSize: 500,
43
+ * diskMaxSize: 5000,
44
44
  * dbName: 'my-app-cache',
45
45
  * })
46
46
  * ```
@@ -4,5 +4,6 @@ declare global {
4
4
  }
5
5
  }
6
6
  export declare function isSafariLoadFailed(error: unknown): boolean;
7
+ export declare function isUnauthorizedError(error: unknown): boolean;
7
8
  export declare function initPromiseErrorExtension(): void;
8
9
  //# sourceMappingURL=PromiseExt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PromiseExt.d.ts","sourceRoot":"","sources":["../../src/flow/PromiseExt.ts"],"names":[],"mappings":"AAIA,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;AAED,wBAAgB,yBAAyB,IAAI,IAAI,CAgDhD"}
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"}
@@ -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 ? filter(error) : !isSafariLoadFailed(error);
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: 200,
57
- diskCacheMaxSize: 1000,
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
- /** 内存缓存最大条目数,默认 200 */
34
+ /** 内存缓存最大条目数,默认 500 */
35
35
  memoryCacheMaxSize?: number;
36
- /** 磁盘缓存最大条目数,默认 1000 */
36
+ /** 磁盘缓存最大条目数,默认 5000 */
37
37
  diskCacheMaxSize?: number;
38
38
  /** IndexedDB 数据库名,默认 'xxf-http-cache' */
39
39
  dbName?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xxf_react",
3
- "version": "0.8.8",
3
+ "version": "0.9.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",