axios 1.7.0-beta.0 → 1.7.0-beta.1

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.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

@@ -18,8 +18,9 @@ const fetchProgressDecorator = (total, fn) => {
18
18
  }
19
19
 
20
20
  const isFetchSupported = typeof fetch !== 'undefined';
21
+ const isReadableStreamSupported = isFetchSupported && typeof ReadableStream !== 'undefined';
21
22
 
22
- const supportsRequestStreams = isFetchSupported && (() => {
23
+ const supportsRequestStream = isReadableStreamSupported && (() => {
23
24
  let duplexAccessed = false;
24
25
 
25
26
  const hasContentType = new Request(platform.origin, {
@@ -36,15 +37,26 @@ const supportsRequestStreams = isFetchSupported && (() => {
36
37
 
37
38
  const DEFAULT_CHUNK_SIZE = 64 * 1024;
38
39
 
40
+ const supportsResponseStream = isReadableStreamSupported && !!(()=> {
41
+ try {
42
+ return utils.isReadableStream(new Response('').body);
43
+ } catch(err) {
44
+ // return undefined
45
+ }
46
+ })();
47
+
39
48
  const resolvers = {
40
- stream: (res) => res.body
49
+ stream: supportsResponseStream && ((res) => res.body)
41
50
  };
42
51
 
43
- isFetchSupported && ['text', 'arrayBuffer', 'blob', 'formData'].forEach(type => [
44
- resolvers[type] = utils.isFunction(Response.prototype[type]) ? (res) => res[type]() : (_, config) => {
45
- throw new AxiosError(`Response type ${type} is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
46
- }
47
- ])
52
+ isFetchSupported && (((res) => {
53
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
54
+ !resolvers[type] && (resolvers[type] = utils.isFunction(res[type]) ? (res) => res[type]() :
55
+ (_, config) => {
56
+ throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
57
+ })
58
+ });
59
+ })(new Response));
48
60
 
49
61
  const getBodyLength = async (body) => {
50
62
  if(utils.isBlob(body)) {
@@ -74,7 +86,7 @@ const resolveBodyLength = async (headers, body) => {
74
86
  return length == null ? getBodyLength(body) : length;
75
87
  }
76
88
 
77
- export default async (config) => {
89
+ export default isFetchSupported && (async (config) => {
78
90
  let {
79
91
  url,
80
92
  method,
@@ -106,7 +118,7 @@ export default async (config) => {
106
118
  }
107
119
 
108
120
  try {
109
- if (onUploadProgress && supportsRequestStreams && method !== 'get' && method !== 'head') {
121
+ if (onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head') {
110
122
  let requestContentLength = await resolveBodyLength(headers, data);
111
123
 
112
124
  let _request = new Request(url, {
@@ -145,7 +157,7 @@ export default async (config) => {
145
157
 
146
158
  const isStreamResponse = responseType === 'stream' || responseType === 'response';
147
159
 
148
- if (onDownloadProgress || isStreamResponse) {
160
+ if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
149
161
  const options = {};
150
162
 
151
163
  Object.getOwnPropertyNames(response).forEach(prop => {
@@ -184,14 +196,17 @@ export default async (config) => {
184
196
  } catch (err) {
185
197
  onFinish();
186
198
 
187
- let {code} = err;
188
-
189
- if (err.name === 'NetworkError') {
190
- code = AxiosError.ERR_NETWORK;
199
+ if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
200
+ throw Object.assign(
201
+ new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
202
+ {
203
+ cause: err.cause || err
204
+ }
205
+ )
191
206
  }
192
207
 
193
- throw AxiosError.from(err, code, config, request);
208
+ throw AxiosError.from(err, err && err.code, config, request);
194
209
  }
195
- }
210
+ });
196
211
 
197
212
 
package/lib/core/Axios.js CHANGED
@@ -46,12 +46,15 @@ class Axios {
46
46
 
47
47
  // slice off the Error: ... line
48
48
  const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
49
-
50
- if (!err.stack) {
51
- err.stack = stack;
52
- // match without the 2 top stack lines
53
- } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
54
- err.stack += '\n' + stack
49
+ try {
50
+ if (!err.stack) {
51
+ err.stack = stack;
52
+ // match without the 2 top stack lines
53
+ } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
54
+ err.stack += '\n' + stack
55
+ }
56
+ } catch (e) {
57
+ // ignore the case where "stack" is an un-writable property
55
58
  }
56
59
  }
57
60
 
package/lib/env/data.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.7.0-beta.0";
1
+ export const VERSION = "1.7.0-beta.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "1.7.0-beta.0",
3
+ "version": "1.7.0-beta.1",
4
4
  "description": "Promise based HTTP client for the browser and node.js",
5
5
  "main": "index.js",
6
6
  "exports": {