@varlet/axle 0.2.11 → 0.2.12

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/README.md CHANGED
@@ -269,6 +269,7 @@ axle.useResponseInterceptor(
269
269
  | [requestHeadersInterceptor](https://github.com/varletjs/axle/blob/main/src/interceptors/examples/requestHeadersInterceptor.md) | Used to customize the request header |
270
270
  | [requestMockInterceptor](https://github.com/varletjs/axle/blob/main/src/interceptors/examples/requestMockInterceptor.md) | Used to mock data |
271
271
  | [responseRetryInterceptor](https://github.com/varletjs/axle/blob/main/src/interceptors/examples/responseRetryInterceptor.md) | Used to realize the request abnormal retry |
272
+ | [responseStatusInterceptor](https://github.com/varletjs/axle/blob/main/src/interceptors/examples/responseStatusInterceptor.md) | Used to intercept status code |
272
273
  | [responseBlobInterceptor](https://github.com/varletjs/axle/blob/main/src/interceptors/examples/responseBlobInterceptor.md) | Used to intercept blob type |
273
274
  | [responseTimeoutInterceptor](https://github.com/varletjs/axle/blob/main/src/interceptors/examples/responseTimeoutInterceptor.md) | Used to abnormal timeout |
274
275
 
package/README.zh-CN.md CHANGED
@@ -269,6 +269,7 @@ axle.useResponseInterceptor(
269
269
  | [requestHeadersInterceptor](https://github.com/varletjs/axle/blob/main/src/interceptors/examples/requestHeadersInterceptor.md) | 用于自定义请求头 |
270
270
  | [requestMockInterceptor](https://github.com/varletjs/axle/blob/main/src/interceptors/examples/requestMockInterceptor.md) | 用于模拟数据 |
271
271
  | [responseRetryInterceptor](https://github.com/varletjs/axle/blob/main/src/interceptors/examples/responseRetryInterceptor.md) | 用于实现请求异常重试 |
272
+ | [responseStatusInterceptor](https://github.com/varletjs/axle/blob/main/src/interceptors/examples/responseStatusInterceptor.md) | 用于拦截状态码 |
272
273
  | [responseBlobInterceptor](https://github.com/varletjs/axle/blob/main/src/interceptors/examples/responseBlobInterceptor.md) | 用于拦截 blob 类型 |
273
274
  | [responseTimeoutInterceptor](https://github.com/varletjs/axle/blob/main/src/interceptors/examples/responseTimeoutInterceptor.md) | 用于归一化超时异常 |
274
275
 
package/es/index.d.ts CHANGED
@@ -54,4 +54,13 @@ interface ResponseRetryInterceptorOptions {
54
54
  }
55
55
  declare function responseRetryInterceptor(options: ResponseRetryInterceptorOptions): ResponseInterceptor;
56
56
 
57
- export { RequestHeadersInterceptorOptions, RequestInterceptor, RequestMockInterceptorMappingValue, RequestMockInterceptorOptions, ResponseBlobInterceptorOptions, ResponseInterceptor, ResponseRetryInterceptorOptions, ResponseTimeoutInterceptorOptions, createMatcher, matchPattern, requestHeadersInterceptor, requestMockInterceptor, responseBlobInterceptor, responseRetryInterceptor, responseTimeoutInterceptor };
57
+ interface ResponseStatusInterceptorOptions {
58
+ validateHandler?: Record<number | string, (response: AxiosResponse<any, any>) => any>;
59
+ invalidateHandler?: Record<number | string, (error: any) => any>;
60
+ include?: string[];
61
+ exclude?: string[];
62
+ axiosInterceptorOptions?: AxiosInterceptorOptions;
63
+ }
64
+ declare function responseStatusInterceptor(options: ResponseStatusInterceptorOptions): ResponseInterceptor;
65
+
66
+ export { RequestHeadersInterceptorOptions, RequestInterceptor, RequestMockInterceptorMappingValue, RequestMockInterceptorOptions, ResponseBlobInterceptorOptions, ResponseInterceptor, ResponseRetryInterceptorOptions, ResponseStatusInterceptorOptions, ResponseTimeoutInterceptorOptions, createMatcher, matchPattern, requestHeadersInterceptor, requestMockInterceptor, responseBlobInterceptor, responseRetryInterceptor, responseStatusInterceptor, responseTimeoutInterceptor };
package/es/index.js CHANGED
@@ -286,6 +286,39 @@ function responseRetryInterceptor(options) {
286
286
  options: options.axiosInterceptorOptions
287
287
  };
288
288
  }
289
+
290
+ // src/interceptors/responseStatusInterceptor.ts
291
+ function responseStatusInterceptor(options) {
292
+ return {
293
+ onFulfilled: (response) => {
294
+ var _a, _b, _c;
295
+ const matcher = createMatcher(options.include, options.exclude);
296
+ if (!matcher((_a = response.config.method) != null ? _a : "", (_b = response.config.url) != null ? _b : "")) {
297
+ return response;
298
+ }
299
+ const handler = ((_c = options.validateHandler) != null ? _c : {})[response.status];
300
+ if (!handler) {
301
+ return response;
302
+ }
303
+ const handlerResponse = handler(response);
304
+ return handlerResponse != null ? handlerResponse : response;
305
+ },
306
+ onRejected: (error) => {
307
+ var _a, _b, _c;
308
+ const matcher = createMatcher(options.include, options.exclude);
309
+ if (!matcher((_a = error.config.method) != null ? _a : "", (_b = error.config.url) != null ? _b : "")) {
310
+ return Promise.reject(error);
311
+ }
312
+ const handler = ((_c = options.invalidateHandler) != null ? _c : {})[error.response.status];
313
+ if (!handler) {
314
+ return Promise.reject(error);
315
+ }
316
+ const handlerError = handler(error);
317
+ return handlerError != null ? handlerError : Promise.reject(error);
318
+ },
319
+ options: options.axiosInterceptorOptions
320
+ };
321
+ }
289
322
  export {
290
323
  createAxle,
291
324
  createFetchRunner,
@@ -297,5 +330,6 @@ export {
297
330
  requestMockInterceptor,
298
331
  responseBlobInterceptor,
299
332
  responseRetryInterceptor,
333
+ responseStatusInterceptor,
300
334
  responseTimeoutInterceptor
301
335
  };
package/es/use.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  import { ref as ref3 } from "vue";
7
7
  import { isFunction } from "@varlet/shared";
8
8
 
9
- // src/useValues.ts
9
+ // src/composables/useValues.ts
10
10
  import { computed } from "vue";
11
11
  function useValues(...valueCollection) {
12
12
  return computed({
@@ -19,7 +19,7 @@ function useValues(...valueCollection) {
19
19
  });
20
20
  }
21
21
 
22
- // src/useHasLoading.ts
22
+ // src/composables/useHasLoading.ts
23
23
  import { ref, watch } from "vue";
24
24
  function useHasLoading(...loadings) {
25
25
  const hasLoading = ref(false);
@@ -33,7 +33,7 @@ function useHasLoading(...loadings) {
33
33
  return hasLoading;
34
34
  }
35
35
 
36
- // src/useAverageProgress.ts
36
+ // src/composables/useAverageProgress.ts
37
37
  import { ref as ref2, watch as watch2 } from "vue";
38
38
  function useAverageProgress(...progressCollection) {
39
39
  const averageProgress = ref2(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/axle",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "description": "Progressive request tool based on axios",
5
5
  "type": "module",
6
6
  "main": "es/index.js",