mhy-http-ts 1.0.1 → 1.0.2

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
@@ -63,7 +63,9 @@ const defaultInterceptors: any = {
63
63
  return code ? Promise.resolve(data) : Promise.reject(data);
64
64
  },
65
65
 
66
- requestCatchHook: (error: AxiosError, config: AxiosRequestConfig) => { ... }
66
+ requestCatchHook: (error: Error | AxiosError, config: AxiosRequestConfig) => {
67
+ return Promise.reject(error)
68
+ }
67
69
  }
68
70
 
69
71
  const defApi = new AxiosCreate(defaultRequestConfig, defaultInterceptors);
@@ -72,9 +74,11 @@ const defApi = new AxiosCreate(defaultRequestConfig, defaultInterceptors);
72
74
  # API
73
75
 
74
76
  ---
77
+
75
78
  ## get
76
79
 
77
80
  ---
81
+
78
82
  ```
79
83
  const getApi = defApi.get({
80
84
  url: '/api/test/get',
@@ -86,6 +90,7 @@ const getApi = defApi.get({
86
90
  ## post
87
91
 
88
92
  ---
93
+
89
94
  ```
90
95
  const postApi = defApi.post({
91
96
  url: '/api/test/post',
@@ -103,6 +108,7 @@ const download = defApi.post({
103
108
  ## put
104
109
 
105
110
  ---
111
+
106
112
  ```
107
113
  const putApi = defApi.post({
108
114
  url: '/api/test/put',
@@ -114,6 +120,7 @@ const putApi = defApi.post({
114
120
  ## delete
115
121
 
116
122
  ---
123
+
117
124
  ```
118
125
  const deleteApi = defApi.post({
119
126
  url: '/api/test/delete',
@@ -125,4 +132,5 @@ const deleteApi = defApi.post({
125
132
  # License
126
133
 
127
134
  ---
128
- MIT
135
+
136
+ MIT
@@ -68,7 +68,7 @@ export class Create {
68
68
  this.instance.interceptors.request.use(
69
69
  (config: InternalAxiosRequestConfig) => {
70
70
  const isAllowRepeat = this.requestConfig?.customOptions?.isAllowRepeat ?? true
71
- // !isAllowRepeat && axiosCanceler.addPending(config)
71
+ !isAllowRepeat && axiosCanceler.addPending(config)
72
72
  if (requestInterceptors && _isFunction(requestInterceptors)) {
73
73
  config = requestInterceptors(config, this.requestConfig)
74
74
  }
@@ -83,7 +83,7 @@ export class Create {
83
83
  // 响应拦截器
84
84
  this.instance.interceptors.response.use(
85
85
  (res: AxiosResponse<any>) => {
86
- // res && axiosCanceler.removePending(res.config)
86
+ res && axiosCanceler.removePending(res.config)
87
87
  if (responseInterceptors && _isFunction(responseInterceptors)) {
88
88
  res = responseInterceptors(res)
89
89
  }
@@ -113,6 +113,7 @@ export class Create {
113
113
  if (afterRequestHook && _isFunction(afterRequestHook)) {
114
114
  try {
115
115
  resolve(afterRequestHook(res))
116
+ return
116
117
  } catch (e: any) {
117
118
  reject(e || new Error('request has error'))
118
119
  }
@@ -123,6 +124,7 @@ export class Create {
123
124
  .catch((error: Error | AxiosError) => {
124
125
  if (requestCatchHook && _isFunction(requestCatchHook)) {
125
126
  reject(requestCatchHook(error, conf))
127
+ return
126
128
  }
127
129
  reject(error)
128
130
  })
@@ -1,12 +1,12 @@
1
1
  import { AxiosRequestConfig } from "axios"
2
2
 
3
3
  export interface RequestConfig extends AxiosRequestConfig {
4
- customOptions: CustomOptions
4
+ customOptions?: CustomOptions
5
5
  }
6
6
 
7
7
  export interface CustomOptions {
8
8
  // 是否需要token
9
- isWithToken?: boolean
9
+ isAuthorized?: boolean
10
10
  // 是否允许重复请求
11
11
  isAllowRepeat?: boolean
12
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mhy-http-ts",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "基于ts的axios二次封装",
5
5
  "main": "./index.ts",
6
6
  "repository": "https://gitee.com/long-leg-kirky/mhy-http-ts",