@varlet/axle 0.2.5 → 0.2.6

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,2 +1,3 @@
1
1
  export * from './requestHeadersInterceptor';
2
2
  export * from './responseBlobInterceptor';
3
+ export * from './responseTimeoutInterceptor';
@@ -1,2 +1,3 @@
1
1
  export * from './requestHeadersInterceptor';
2
2
  export * from './responseBlobInterceptor';
3
+ export * from './responseTimeoutInterceptor';
@@ -13,6 +13,6 @@ export function requestHeadersInterceptor(options = {}) {
13
13
  onRejected(error) {
14
14
  return Promise.reject(error);
15
15
  },
16
- options: options.axiosInterceptorOptions
16
+ options: options.axiosInterceptorOptions,
17
17
  };
18
18
  }
@@ -0,0 +1,7 @@
1
+ import type { AxiosInterceptorOptions } from 'axios';
2
+ import type { ResponseInterceptor } from '../instance';
3
+ export interface ResponseTimeoutInterceptorOptions {
4
+ normalizeErrorCode?: string;
5
+ axiosInterceptorOptions?: AxiosInterceptorOptions;
6
+ }
7
+ export declare function responseTimeoutInterceptor(options?: ResponseTimeoutInterceptorOptions): ResponseInterceptor;
@@ -0,0 +1,15 @@
1
+ export function responseTimeoutInterceptor(options = {}) {
2
+ return {
3
+ onFulfilled(response) {
4
+ return response;
5
+ },
6
+ onRejected(error) {
7
+ var _a;
8
+ if ((error.code == 'ECONNABORTED' && error.message.includes('timeout')) || error.code === 'ETIMEDOUT') {
9
+ error.code = (_a = options === null || options === void 0 ? void 0 : options.normalizeErrorCode) !== null && _a !== void 0 ? _a : 'TIMEOUT';
10
+ }
11
+ return Promise.reject(error);
12
+ },
13
+ options: options.axiosInterceptorOptions,
14
+ };
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/axle",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Progressive request tool based on axios",
5
5
  "type": "module",
6
6
  "main": "es/index.js",