@jetlinks-web/core 2.2.5 → 2.2.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetlinks-web/core",
3
- "version": "2.2.5",
3
+ "version": "2.2.7",
4
4
  "main": "index.ts",
5
5
  "module": "index.ts",
6
6
  "keywords": [
package/src/axios.ts CHANGED
@@ -189,8 +189,8 @@ const errorHandler = async (err: AxiosError<any>) => {
189
189
  description = (`${data?.message}`).substring(0, 90)
190
190
  break;
191
191
  case 401:
192
- description = err.response.data.result.text || '用户未登录';
193
- _options.tokenExpiration?.()
192
+ description = err.response.data.result?.text || '用户未登录';
193
+ _options.tokenExpiration?.(err)
194
194
  if(_options.isCreateTokenRefresh){
195
195
  return createTokenRefreshHandler(err)
196
196
  }
package/src/fetch.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import {getToken} from "@jetlinks-web/utils";
2
2
  import {BASE_API, TOKEN_KEY} from "@jetlinks-web/constants";
3
- import {isFunction, isObject, isString} from "lodash-es";
3
+ import {isFunction, isObject} from "lodash-es";
4
4
  import { Observable, } from 'rxjs'
5
5
 
6
6
  const controller = new AbortController();
7
7
 
8
- class NdJson {
8
+ export class NdJson {
9
9
  options: any = {
10
10
  code: 200,
11
11
  codeKey: 'status'
@@ -22,11 +22,10 @@ class NdJson {
22
22
  }
23
23
 
24
24
  get(url, data = '{}', extra = {}) {
25
+ const _url = this.getUrl(url)
25
26
  const that = this
26
27
  return new Observable(observer => {
27
- const _url = that.getUrl(url)
28
- const that = this
29
-
28
+ let reader
30
29
  fetch(
31
30
  _url,
32
31
  {
@@ -37,7 +36,7 @@ class NdJson {
37
36
  ...this.handleRequest(_url)
38
37
  }
39
38
  ).then(resp => {
40
- const reader = resp.body?.getReader();
39
+ reader = resp.body?.getReader();
41
40
  const decoder = new TextDecoder();
42
41
  let data_buf = "";
43
42
 
@@ -92,6 +91,10 @@ class NdJson {
92
91
  }).catch(e => {
93
92
  observer.error(e)
94
93
  })
94
+
95
+ return () => {
96
+ that.cancel()
97
+ }
95
98
  })
96
99
  }
97
100
 
@@ -100,6 +103,7 @@ class NdJson {
100
103
  const that = this
101
104
 
102
105
  return new Observable(observer => {
106
+ let reader
103
107
  fetch(
104
108
  _url,
105
109
  {
@@ -111,7 +115,7 @@ class NdJson {
111
115
  ...this.handleRequest(_url)
112
116
  }
113
117
  ).then(async resp => {
114
- const reader = resp.body?.getReader();
118
+ reader = resp.body?.getReader();
115
119
  const decoder = new TextDecoder();
116
120
  let data_buf = "";
117
121
 
@@ -166,6 +170,10 @@ class NdJson {
166
170
  }).catch(e => {
167
171
  observer.error(e)
168
172
  })
173
+
174
+ return () => {
175
+ that.cancel()
176
+ }
169
177
  })
170
178
  }
171
179
  handleRequest(url): RequestInit {
@@ -213,9 +221,8 @@ class NdJson {
213
221
  cancel() {
214
222
  if (this.isRead) {
215
223
  this.isRead = false
216
- } else {
217
- controller.abort()
218
224
  }
225
+ controller.abort()
219
226
  }
220
227
  }
221
228