axios 0.26.1 → 0.27.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/CHANGELOG.md +49 -12
- package/README.md +114 -32
- package/dist/axios.js +479 -177
- package/dist/axios.map +1 -1
- package/dist/axios.min.js +2 -1
- package/dist/axios.min.map +1 -1
- package/index.d.ts +37 -4
- package/lib/adapters/http.js +47 -27
- package/lib/adapters/xhr.js +18 -8
- package/lib/axios.js +8 -1
- package/lib/cancel/CancelToken.js +3 -3
- package/lib/cancel/CanceledError.js +22 -0
- package/lib/core/Axios.js +20 -8
- package/lib/core/AxiosError.js +86 -0
- package/lib/core/dispatchRequest.js +3 -3
- package/lib/core/mergeConfig.js +1 -0
- package/lib/core/settle.js +3 -3
- package/lib/defaults/env/FormData.js +2 -0
- package/lib/defaults/index.js +18 -3
- package/lib/env/data.js +1 -1
- package/lib/helpers/null.js +2 -0
- package/lib/helpers/parseProtocol.js +6 -0
- package/lib/helpers/toFormData.js +63 -46
- package/lib/helpers/validator.js +8 -4
- package/lib/utils.js +148 -27
- package/package.json +25 -24
- package/lib/cancel/Cancel.js +0 -19
- package/lib/core/createError.js +0 -18
- package/lib/core/enhanceError.js +0 -43
package/lib/adapters/http.js
CHANGED
@@ -11,13 +11,14 @@ var httpsFollow = require('follow-redirects').https;
|
|
11
11
|
var url = require('url');
|
12
12
|
var zlib = require('zlib');
|
13
13
|
var VERSION = require('./../env/data').version;
|
14
|
-
var createError = require('../core/createError');
|
15
|
-
var enhanceError = require('../core/enhanceError');
|
16
14
|
var transitionalDefaults = require('../defaults/transitional');
|
17
|
-
var
|
15
|
+
var AxiosError = require('../core/AxiosError');
|
16
|
+
var CanceledError = require('../cancel/CanceledError');
|
18
17
|
|
19
18
|
var isHttps = /https:?/;
|
20
19
|
|
20
|
+
var supportedProtocols = [ 'http:', 'https:', 'file:' ];
|
21
|
+
|
21
22
|
/**
|
22
23
|
*
|
23
24
|
* @param {http.ClientRequestArgs} options
|
@@ -87,7 +88,10 @@ module.exports = function httpAdapter(config) {
|
|
87
88
|
headers['User-Agent'] = 'axios/' + VERSION;
|
88
89
|
}
|
89
90
|
|
90
|
-
|
91
|
+
// support for https://www.npmjs.com/package/form-data api
|
92
|
+
if (utils.isFormData(data) && utils.isFunction(data.getHeaders)) {
|
93
|
+
Object.assign(headers, data.getHeaders());
|
94
|
+
} else if (data && !utils.isStream(data)) {
|
91
95
|
if (Buffer.isBuffer(data)) {
|
92
96
|
// Nothing to do...
|
93
97
|
} else if (utils.isArrayBuffer(data)) {
|
@@ -95,14 +99,19 @@ module.exports = function httpAdapter(config) {
|
|
95
99
|
} else if (utils.isString(data)) {
|
96
100
|
data = Buffer.from(data, 'utf-8');
|
97
101
|
} else {
|
98
|
-
return reject(
|
102
|
+
return reject(new AxiosError(
|
99
103
|
'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
|
104
|
+
AxiosError.ERR_BAD_REQUEST,
|
100
105
|
config
|
101
106
|
));
|
102
107
|
}
|
103
108
|
|
104
109
|
if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
|
105
|
-
return reject(
|
110
|
+
return reject(new AxiosError(
|
111
|
+
'Request body larger than maxBodyLength limit',
|
112
|
+
AxiosError.ERR_BAD_REQUEST,
|
113
|
+
config
|
114
|
+
));
|
106
115
|
}
|
107
116
|
|
108
117
|
// Add Content-Length header if data exists
|
@@ -122,7 +131,15 @@ module.exports = function httpAdapter(config) {
|
|
122
131
|
// Parse url
|
123
132
|
var fullPath = buildFullPath(config.baseURL, config.url);
|
124
133
|
var parsed = url.parse(fullPath);
|
125
|
-
var protocol = parsed.protocol ||
|
134
|
+
var protocol = parsed.protocol || supportedProtocols[0];
|
135
|
+
|
136
|
+
if (supportedProtocols.indexOf(protocol) === -1) {
|
137
|
+
return reject(new AxiosError(
|
138
|
+
'Unsupported protocol ' + protocol,
|
139
|
+
AxiosError.ERR_BAD_REQUEST,
|
140
|
+
config
|
141
|
+
));
|
142
|
+
}
|
126
143
|
|
127
144
|
if (!auth && parsed.auth) {
|
128
145
|
var urlAuth = parsed.auth.split(':');
|
@@ -227,6 +244,9 @@ module.exports = function httpAdapter(config) {
|
|
227
244
|
if (config.maxRedirects) {
|
228
245
|
options.maxRedirects = config.maxRedirects;
|
229
246
|
}
|
247
|
+
if (config.beforeRedirect) {
|
248
|
+
options.beforeRedirect = config.beforeRedirect;
|
249
|
+
}
|
230
250
|
transport = isHttpsProxy ? httpsFollow : httpFollow;
|
231
251
|
}
|
232
252
|
|
@@ -288,8 +308,8 @@ module.exports = function httpAdapter(config) {
|
|
288
308
|
// stream.destoy() emit aborted event before calling reject() on Node.js v16
|
289
309
|
rejected = true;
|
290
310
|
stream.destroy();
|
291
|
-
reject(
|
292
|
-
|
311
|
+
reject(new AxiosError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
312
|
+
AxiosError.ERR_BAD_RESPONSE, config, lastRequest));
|
293
313
|
}
|
294
314
|
});
|
295
315
|
|
@@ -298,12 +318,17 @@ module.exports = function httpAdapter(config) {
|
|
298
318
|
return;
|
299
319
|
}
|
300
320
|
stream.destroy();
|
301
|
-
reject(
|
321
|
+
reject(new AxiosError(
|
322
|
+
'maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
323
|
+
AxiosError.ERR_BAD_RESPONSE,
|
324
|
+
config,
|
325
|
+
lastRequest
|
326
|
+
));
|
302
327
|
});
|
303
328
|
|
304
329
|
stream.on('error', function handleStreamError(err) {
|
305
330
|
if (req.aborted) return;
|
306
|
-
reject(
|
331
|
+
reject(AxiosError.from(err, null, config, lastRequest));
|
307
332
|
});
|
308
333
|
|
309
334
|
stream.on('end', function handleStreamEnd() {
|
@@ -317,7 +342,7 @@ module.exports = function httpAdapter(config) {
|
|
317
342
|
}
|
318
343
|
response.data = responseData;
|
319
344
|
} catch (err) {
|
320
|
-
reject(
|
345
|
+
reject(AxiosError.from(err, null, config, response.request, response));
|
321
346
|
}
|
322
347
|
settle(resolve, reject, response);
|
323
348
|
});
|
@@ -326,8 +351,9 @@ module.exports = function httpAdapter(config) {
|
|
326
351
|
|
327
352
|
// Handle errors
|
328
353
|
req.on('error', function handleRequestError(err) {
|
329
|
-
|
330
|
-
|
354
|
+
// @todo remove
|
355
|
+
// if (req.aborted && err.code !== AxiosError.ERR_FR_TOO_MANY_REDIRECTS) return;
|
356
|
+
reject(AxiosError.from(err, null, config, req));
|
331
357
|
});
|
332
358
|
|
333
359
|
// set tcp keep alive to prevent drop connection by peer
|
@@ -342,10 +368,10 @@ module.exports = function httpAdapter(config) {
|
|
342
368
|
var timeout = parseInt(config.timeout, 10);
|
343
369
|
|
344
370
|
if (isNaN(timeout)) {
|
345
|
-
reject(
|
371
|
+
reject(new AxiosError(
|
346
372
|
'error trying to parse `config.timeout` to int',
|
373
|
+
AxiosError.ERR_BAD_OPTION_VALUE,
|
347
374
|
config,
|
348
|
-
'ERR_PARSE_TIMEOUT',
|
349
375
|
req
|
350
376
|
));
|
351
377
|
|
@@ -359,17 +385,11 @@ module.exports = function httpAdapter(config) {
|
|
359
385
|
// ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
|
360
386
|
req.setTimeout(timeout, function handleRequestTimeout() {
|
361
387
|
req.abort();
|
362
|
-
var timeoutErrorMessage = '';
|
363
|
-
if (config.timeoutErrorMessage) {
|
364
|
-
timeoutErrorMessage = config.timeoutErrorMessage;
|
365
|
-
} else {
|
366
|
-
timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
|
367
|
-
}
|
368
388
|
var transitional = config.transitional || transitionalDefaults;
|
369
|
-
reject(
|
370
|
-
|
389
|
+
reject(new AxiosError(
|
390
|
+
'timeout of ' + timeout + 'ms exceeded',
|
391
|
+
transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
|
371
392
|
config,
|
372
|
-
transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
|
373
393
|
req
|
374
394
|
));
|
375
395
|
});
|
@@ -382,7 +402,7 @@ module.exports = function httpAdapter(config) {
|
|
382
402
|
if (req.aborted) return;
|
383
403
|
|
384
404
|
req.abort();
|
385
|
-
reject(!cancel || (cancel && cancel.type) ? new
|
405
|
+
reject(!cancel || (cancel && cancel.type) ? new CanceledError() : cancel);
|
386
406
|
};
|
387
407
|
|
388
408
|
config.cancelToken && config.cancelToken.subscribe(onCanceled);
|
@@ -395,7 +415,7 @@ module.exports = function httpAdapter(config) {
|
|
395
415
|
// Send the request
|
396
416
|
if (utils.isStream(data)) {
|
397
417
|
data.on('error', function handleStreamError(err) {
|
398
|
-
reject(
|
418
|
+
reject(AxiosError.from(err, config, null, req));
|
399
419
|
}).pipe(req);
|
400
420
|
} else {
|
401
421
|
req.end(data);
|
package/lib/adapters/xhr.js
CHANGED
@@ -7,9 +7,10 @@ var buildURL = require('./../helpers/buildURL');
|
|
7
7
|
var buildFullPath = require('../core/buildFullPath');
|
8
8
|
var parseHeaders = require('./../helpers/parseHeaders');
|
9
9
|
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
10
|
-
var createError = require('../core/createError');
|
11
10
|
var transitionalDefaults = require('../defaults/transitional');
|
12
|
-
var
|
11
|
+
var AxiosError = require('../core/AxiosError');
|
12
|
+
var CanceledError = require('../cancel/CanceledError');
|
13
|
+
var parseProtocol = require('../helpers/parseProtocol');
|
13
14
|
|
14
15
|
module.exports = function xhrAdapter(config) {
|
15
16
|
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
@@ -27,7 +28,7 @@ module.exports = function xhrAdapter(config) {
|
|
27
28
|
}
|
28
29
|
}
|
29
30
|
|
30
|
-
if (utils.isFormData(requestData)) {
|
31
|
+
if (utils.isFormData(requestData) && utils.isStandardBrowserEnv()) {
|
31
32
|
delete requestHeaders['Content-Type']; // Let the browser set it
|
32
33
|
}
|
33
34
|
|
@@ -41,6 +42,7 @@ module.exports = function xhrAdapter(config) {
|
|
41
42
|
}
|
42
43
|
|
43
44
|
var fullPath = buildFullPath(config.baseURL, config.url);
|
45
|
+
|
44
46
|
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
45
47
|
|
46
48
|
// Set the request timeout in MS
|
@@ -104,7 +106,7 @@ module.exports = function xhrAdapter(config) {
|
|
104
106
|
return;
|
105
107
|
}
|
106
108
|
|
107
|
-
reject(
|
109
|
+
reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
|
108
110
|
|
109
111
|
// Clean up request
|
110
112
|
request = null;
|
@@ -114,7 +116,7 @@ module.exports = function xhrAdapter(config) {
|
|
114
116
|
request.onerror = function handleError() {
|
115
117
|
// Real errors are hidden from us by the browser
|
116
118
|
// onerror should only fire if it's a network error
|
117
|
-
reject(
|
119
|
+
reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request, request));
|
118
120
|
|
119
121
|
// Clean up request
|
120
122
|
request = null;
|
@@ -127,10 +129,10 @@ module.exports = function xhrAdapter(config) {
|
|
127
129
|
if (config.timeoutErrorMessage) {
|
128
130
|
timeoutErrorMessage = config.timeoutErrorMessage;
|
129
131
|
}
|
130
|
-
reject(
|
132
|
+
reject(new AxiosError(
|
131
133
|
timeoutErrorMessage,
|
134
|
+
transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
|
132
135
|
config,
|
133
|
-
transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
|
134
136
|
request));
|
135
137
|
|
136
138
|
// Clean up request
|
@@ -191,7 +193,7 @@ module.exports = function xhrAdapter(config) {
|
|
191
193
|
if (!request) {
|
192
194
|
return;
|
193
195
|
}
|
194
|
-
reject(!cancel || (cancel && cancel.type) ? new
|
196
|
+
reject(!cancel || (cancel && cancel.type) ? new CanceledError() : cancel);
|
195
197
|
request.abort();
|
196
198
|
request = null;
|
197
199
|
};
|
@@ -206,6 +208,14 @@ module.exports = function xhrAdapter(config) {
|
|
206
208
|
requestData = null;
|
207
209
|
}
|
208
210
|
|
211
|
+
var protocol = parseProtocol(fullPath);
|
212
|
+
|
213
|
+
if (protocol && [ 'http', 'https', 'file' ].indexOf(protocol) === -1) {
|
214
|
+
reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
|
215
|
+
return;
|
216
|
+
}
|
217
|
+
|
218
|
+
|
209
219
|
// Send the request
|
210
220
|
request.send(requestData);
|
211
221
|
});
|
package/lib/axios.js
CHANGED
@@ -37,10 +37,17 @@ var axios = createInstance(defaults);
|
|
37
37
|
axios.Axios = Axios;
|
38
38
|
|
39
39
|
// Expose Cancel & CancelToken
|
40
|
-
axios.
|
40
|
+
axios.CanceledError = require('./cancel/CanceledError');
|
41
41
|
axios.CancelToken = require('./cancel/CancelToken');
|
42
42
|
axios.isCancel = require('./cancel/isCancel');
|
43
43
|
axios.VERSION = require('./env/data').version;
|
44
|
+
axios.toFormData = require('./helpers/toFormData');
|
45
|
+
|
46
|
+
// Expose AxiosError class
|
47
|
+
axios.AxiosError = require('../lib/core/AxiosError');
|
48
|
+
|
49
|
+
// alias for CanceledError for backward compatibility
|
50
|
+
axios.Cancel = axios.CanceledError;
|
44
51
|
|
45
52
|
// Expose all/spread
|
46
53
|
axios.all = function all(promises) {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var
|
3
|
+
var CanceledError = require('./CanceledError');
|
4
4
|
|
5
5
|
/**
|
6
6
|
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
@@ -56,13 +56,13 @@ function CancelToken(executor) {
|
|
56
56
|
return;
|
57
57
|
}
|
58
58
|
|
59
|
-
token.reason = new
|
59
|
+
token.reason = new CanceledError(message);
|
60
60
|
resolvePromise(token.reason);
|
61
61
|
});
|
62
62
|
}
|
63
63
|
|
64
64
|
/**
|
65
|
-
* Throws a `
|
65
|
+
* Throws a `CanceledError` if cancellation has been requested.
|
66
66
|
*/
|
67
67
|
CancelToken.prototype.throwIfRequested = function throwIfRequested() {
|
68
68
|
if (this.reason) {
|
@@ -0,0 +1,22 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var AxiosError = require('../core/AxiosError');
|
4
|
+
var utils = require('../utils');
|
5
|
+
|
6
|
+
/**
|
7
|
+
* A `CanceledError` is an object that is thrown when an operation is canceled.
|
8
|
+
*
|
9
|
+
* @class
|
10
|
+
* @param {string=} message The message.
|
11
|
+
*/
|
12
|
+
function CanceledError(message) {
|
13
|
+
// eslint-disable-next-line no-eq-null,eqeqeq
|
14
|
+
AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED);
|
15
|
+
this.name = 'CanceledError';
|
16
|
+
}
|
17
|
+
|
18
|
+
utils.inherits(CanceledError, AxiosError, {
|
19
|
+
__CANCEL__: true
|
20
|
+
});
|
21
|
+
|
22
|
+
module.exports = CanceledError;
|
package/lib/core/Axios.js
CHANGED
@@ -5,6 +5,7 @@ var buildURL = require('../helpers/buildURL');
|
|
5
5
|
var InterceptorManager = require('./InterceptorManager');
|
6
6
|
var dispatchRequest = require('./dispatchRequest');
|
7
7
|
var mergeConfig = require('./mergeConfig');
|
8
|
+
var buildFullPath = require('./buildFullPath');
|
8
9
|
var validator = require('../helpers/validator');
|
9
10
|
|
10
11
|
var validators = validator.validators;
|
@@ -119,7 +120,8 @@ Axios.prototype.request = function request(configOrUrl, config) {
|
|
119
120
|
|
120
121
|
Axios.prototype.getUri = function getUri(config) {
|
121
122
|
config = mergeConfig(this.defaults, config);
|
122
|
-
|
123
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
124
|
+
return buildURL(fullPath, config.params, config.paramsSerializer);
|
123
125
|
};
|
124
126
|
|
125
127
|
// Provide aliases for supported request methods
|
@@ -136,13 +138,23 @@ utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData
|
|
136
138
|
|
137
139
|
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
138
140
|
/*eslint func-names:0*/
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
141
|
+
|
142
|
+
function generateHTTPMethod(isForm) {
|
143
|
+
return function httpMethod(url, data, config) {
|
144
|
+
return this.request(mergeConfig(config || {}, {
|
145
|
+
method: method,
|
146
|
+
headers: isForm ? {
|
147
|
+
'Content-Type': 'multipart/form-data'
|
148
|
+
} : {},
|
149
|
+
url: url,
|
150
|
+
data: data
|
151
|
+
}));
|
152
|
+
};
|
153
|
+
}
|
154
|
+
|
155
|
+
Axios.prototype[method] = generateHTTPMethod();
|
156
|
+
|
157
|
+
Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
146
158
|
});
|
147
159
|
|
148
160
|
module.exports = Axios;
|
@@ -0,0 +1,86 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var utils = require('../utils');
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Create an Error with the specified message, config, error code, request and response.
|
7
|
+
*
|
8
|
+
* @param {string} message The error message.
|
9
|
+
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
10
|
+
* @param {Object} [config] The config.
|
11
|
+
* @param {Object} [request] The request.
|
12
|
+
* @param {Object} [response] The response.
|
13
|
+
* @returns {Error} The created error.
|
14
|
+
*/
|
15
|
+
function AxiosError(message, code, config, request, response) {
|
16
|
+
Error.call(this);
|
17
|
+
this.message = message;
|
18
|
+
this.name = 'AxiosError';
|
19
|
+
code && (this.code = code);
|
20
|
+
config && (this.config = config);
|
21
|
+
request && (this.request = request);
|
22
|
+
response && (this.response = response);
|
23
|
+
}
|
24
|
+
|
25
|
+
utils.inherits(AxiosError, Error, {
|
26
|
+
toJSON: function toJSON() {
|
27
|
+
return {
|
28
|
+
// Standard
|
29
|
+
message: this.message,
|
30
|
+
name: this.name,
|
31
|
+
// Microsoft
|
32
|
+
description: this.description,
|
33
|
+
number: this.number,
|
34
|
+
// Mozilla
|
35
|
+
fileName: this.fileName,
|
36
|
+
lineNumber: this.lineNumber,
|
37
|
+
columnNumber: this.columnNumber,
|
38
|
+
stack: this.stack,
|
39
|
+
// Axios
|
40
|
+
config: this.config,
|
41
|
+
code: this.code,
|
42
|
+
status: this.response && this.response.status ? this.response.status : null
|
43
|
+
};
|
44
|
+
}
|
45
|
+
});
|
46
|
+
|
47
|
+
var prototype = AxiosError.prototype;
|
48
|
+
var descriptors = {};
|
49
|
+
|
50
|
+
[
|
51
|
+
'ERR_BAD_OPTION_VALUE',
|
52
|
+
'ERR_BAD_OPTION',
|
53
|
+
'ECONNABORTED',
|
54
|
+
'ETIMEDOUT',
|
55
|
+
'ERR_NETWORK',
|
56
|
+
'ERR_FR_TOO_MANY_REDIRECTS',
|
57
|
+
'ERR_DEPRECATED',
|
58
|
+
'ERR_BAD_RESPONSE',
|
59
|
+
'ERR_BAD_REQUEST',
|
60
|
+
'ERR_CANCELED'
|
61
|
+
// eslint-disable-next-line func-names
|
62
|
+
].forEach(function(code) {
|
63
|
+
descriptors[code] = {value: code};
|
64
|
+
});
|
65
|
+
|
66
|
+
Object.defineProperties(AxiosError, descriptors);
|
67
|
+
Object.defineProperty(prototype, 'isAxiosError', {value: true});
|
68
|
+
|
69
|
+
// eslint-disable-next-line func-names
|
70
|
+
AxiosError.from = function(error, code, config, request, response, customProps) {
|
71
|
+
var axiosError = Object.create(prototype);
|
72
|
+
|
73
|
+
utils.toFlatObject(error, axiosError, function filter(obj) {
|
74
|
+
return obj !== Error.prototype;
|
75
|
+
});
|
76
|
+
|
77
|
+
AxiosError.call(axiosError, error.message, code, config, request, response);
|
78
|
+
|
79
|
+
axiosError.name = error.name;
|
80
|
+
|
81
|
+
customProps && Object.assign(axiosError, customProps);
|
82
|
+
|
83
|
+
return axiosError;
|
84
|
+
};
|
85
|
+
|
86
|
+
module.exports = AxiosError;
|
@@ -4,10 +4,10 @@ var utils = require('./../utils');
|
|
4
4
|
var transformData = require('./transformData');
|
5
5
|
var isCancel = require('../cancel/isCancel');
|
6
6
|
var defaults = require('../defaults');
|
7
|
-
var
|
7
|
+
var CanceledError = require('../cancel/CanceledError');
|
8
8
|
|
9
9
|
/**
|
10
|
-
* Throws a `
|
10
|
+
* Throws a `CanceledError` if cancellation has been requested.
|
11
11
|
*/
|
12
12
|
function throwIfCancellationRequested(config) {
|
13
13
|
if (config.cancelToken) {
|
@@ -15,7 +15,7 @@ function throwIfCancellationRequested(config) {
|
|
15
15
|
}
|
16
16
|
|
17
17
|
if (config.signal && config.signal.aborted) {
|
18
|
-
throw new
|
18
|
+
throw new CanceledError();
|
19
19
|
}
|
20
20
|
}
|
21
21
|
|
package/lib/core/mergeConfig.js
CHANGED
@@ -80,6 +80,7 @@ module.exports = function mergeConfig(config1, config2) {
|
|
80
80
|
'decompress': defaultToConfig2,
|
81
81
|
'maxContentLength': defaultToConfig2,
|
82
82
|
'maxBodyLength': defaultToConfig2,
|
83
|
+
'beforeRedirect': defaultToConfig2,
|
83
84
|
'transport': defaultToConfig2,
|
84
85
|
'httpAgent': defaultToConfig2,
|
85
86
|
'httpsAgent': defaultToConfig2,
|
package/lib/core/settle.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var
|
3
|
+
var AxiosError = require('./AxiosError');
|
4
4
|
|
5
5
|
/**
|
6
6
|
* Resolve or reject a Promise based on response status.
|
@@ -14,10 +14,10 @@ module.exports = function settle(resolve, reject, response) {
|
|
14
14
|
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
15
15
|
resolve(response);
|
16
16
|
} else {
|
17
|
-
reject(
|
17
|
+
reject(new AxiosError(
|
18
18
|
'Request failed with status code ' + response.status,
|
19
|
+
[AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
|
19
20
|
response.config,
|
20
|
-
null,
|
21
21
|
response.request,
|
22
22
|
response
|
23
23
|
));
|
package/lib/defaults/index.js
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
|
3
3
|
var utils = require('../utils');
|
4
4
|
var normalizeHeaderName = require('../helpers/normalizeHeaderName');
|
5
|
-
var
|
5
|
+
var AxiosError = require('../core/AxiosError');
|
6
6
|
var transitionalDefaults = require('./transitional');
|
7
|
+
var toFormData = require('../helpers/toFormData');
|
7
8
|
|
8
9
|
var DEFAULT_CONTENT_TYPE = {
|
9
10
|
'Content-Type': 'application/x-www-form-urlencoded'
|
@@ -68,10 +69,20 @@ var defaults = {
|
|
68
69
|
setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
|
69
70
|
return data.toString();
|
70
71
|
}
|
71
|
-
|
72
|
+
|
73
|
+
var isObjectPayload = utils.isObject(data);
|
74
|
+
var contentType = headers && headers['Content-Type'];
|
75
|
+
|
76
|
+
var isFileList;
|
77
|
+
|
78
|
+
if ((isFileList = utils.isFileList(data)) || (isObjectPayload && contentType === 'multipart/form-data')) {
|
79
|
+
var _FormData = this.env && this.env.FormData;
|
80
|
+
return toFormData(isFileList ? {'files[]': data} : data, _FormData && new _FormData());
|
81
|
+
} else if (isObjectPayload || contentType === 'application/json') {
|
72
82
|
setContentTypeIfUnset(headers, 'application/json');
|
73
83
|
return stringifySafely(data);
|
74
84
|
}
|
85
|
+
|
75
86
|
return data;
|
76
87
|
}],
|
77
88
|
|
@@ -87,7 +98,7 @@ var defaults = {
|
|
87
98
|
} catch (e) {
|
88
99
|
if (strictJSONParsing) {
|
89
100
|
if (e.name === 'SyntaxError') {
|
90
|
-
throw
|
101
|
+
throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
|
91
102
|
}
|
92
103
|
throw e;
|
93
104
|
}
|
@@ -109,6 +120,10 @@ var defaults = {
|
|
109
120
|
maxContentLength: -1,
|
110
121
|
maxBodyLength: -1,
|
111
122
|
|
123
|
+
env: {
|
124
|
+
FormData: require('./env/FormData')
|
125
|
+
},
|
126
|
+
|
112
127
|
validateStatus: function validateStatus(status) {
|
113
128
|
return status >= 200 && status < 300;
|
114
129
|
},
|
package/lib/env/data.js
CHANGED