axios 0.21.4 → 0.30.0

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +318 -54
  2. package/README.md +378 -64
  3. package/SECURITY.md +3 -3
  4. package/UPGRADE_GUIDE.md +41 -13
  5. package/bin/check-build-version.js +19 -0
  6. package/bin/ssl_hotfix.js +22 -0
  7. package/dist/axios.js +2072 -1878
  8. package/dist/axios.js.map +1 -0
  9. package/dist/axios.min.js +2 -3
  10. package/dist/axios.min.js.map +1 -0
  11. package/dist/esm/axios.js +2379 -0
  12. package/dist/esm/axios.js.map +1 -0
  13. package/dist/esm/axios.min.js +2 -0
  14. package/dist/esm/axios.min.js.map +1 -0
  15. package/index.d.ts +219 -46
  16. package/lib/adapters/http.js +262 -130
  17. package/lib/adapters/xhr.js +59 -22
  18. package/lib/axios.js +19 -7
  19. package/lib/cancel/CancelToken.js +65 -4
  20. package/lib/cancel/CanceledError.js +24 -0
  21. package/lib/core/Axios.js +45 -17
  22. package/lib/core/AxiosError.js +97 -0
  23. package/lib/core/InterceptorManager.js +9 -0
  24. package/lib/core/buildFullPath.js +5 -2
  25. package/lib/core/dispatchRequest.js +13 -1
  26. package/lib/core/mergeConfig.js +54 -38
  27. package/lib/core/settle.js +3 -3
  28. package/lib/core/transformData.js +4 -3
  29. package/lib/{defaults.js → defaults/index.js} +64 -23
  30. package/lib/defaults/transitional.js +7 -0
  31. package/lib/env/README.md +3 -0
  32. package/lib/env/classes/FormData.js +2 -0
  33. package/lib/env/data.js +3 -0
  34. package/lib/helpers/AxiosURLSearchParams.js +42 -0
  35. package/lib/helpers/bind.js +1 -5
  36. package/lib/helpers/buildURL.js +18 -33
  37. package/lib/helpers/combineURLs.js +1 -1
  38. package/lib/helpers/formDataToJSON.js +74 -0
  39. package/lib/helpers/fromDataURI.js +51 -0
  40. package/lib/helpers/isAbsoluteURL.js +1 -1
  41. package/lib/helpers/isAxiosError.js +3 -1
  42. package/lib/helpers/isURLSameOrigin.js +12 -12
  43. package/lib/helpers/null.js +2 -0
  44. package/lib/helpers/parseHeaders.js +2 -2
  45. package/lib/helpers/parseProtocol.js +6 -0
  46. package/lib/helpers/toFormData.js +179 -0
  47. package/lib/helpers/toURLEncodedForm.js +18 -0
  48. package/lib/helpers/validator.js +14 -33
  49. package/lib/platform/browser/classes/FormData.js +3 -0
  50. package/lib/platform/browser/classes/URLSearchParams.js +5 -0
  51. package/lib/platform/browser/index.js +11 -0
  52. package/lib/platform/index.js +3 -0
  53. package/lib/platform/node/classes/FormData.js +3 -0
  54. package/lib/platform/node/classes/URLSearchParams.js +5 -0
  55. package/lib/platform/node/index.js +11 -0
  56. package/lib/utils.js +210 -37
  57. package/package.json +42 -26
  58. package/rollup.config.js +60 -0
  59. package/tsconfig.json +14 -0
  60. package/tslint.json +6 -0
  61. package/dist/axios.map +0 -1
  62. package/dist/axios.min.map +0 -1
  63. package/lib/cancel/Cancel.js +0 -19
  64. package/lib/core/createError.js +0 -18
  65. package/lib/core/enhanceError.js +0 -42
@@ -7,15 +7,30 @@ 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');
10
+ var transitionalDefaults = require('../defaults/transitional');
11
+ var AxiosError = require('../core/AxiosError');
12
+ var CanceledError = require('../cancel/CanceledError');
13
+ var parseProtocol = require('../helpers/parseProtocol');
14
+ var platform = require('../platform');
11
15
 
12
16
  module.exports = function xhrAdapter(config) {
13
17
  return new Promise(function dispatchXhrRequest(resolve, reject) {
14
18
  var requestData = config.data;
15
19
  var requestHeaders = config.headers;
16
20
  var responseType = config.responseType;
21
+ var withXSRFToken = config.withXSRFToken;
22
+ var onCanceled;
23
+ function done() {
24
+ if (config.cancelToken) {
25
+ config.cancelToken.unsubscribe(onCanceled);
26
+ }
27
+
28
+ if (config.signal) {
29
+ config.signal.removeEventListener('abort', onCanceled);
30
+ }
31
+ }
17
32
 
18
- if (utils.isFormData(requestData)) {
33
+ if (utils.isFormData(requestData) && utils.isStandardBrowserEnv()) {
19
34
  delete requestHeaders['Content-Type']; // Let the browser set it
20
35
  }
21
36
 
@@ -28,7 +43,8 @@ module.exports = function xhrAdapter(config) {
28
43
  requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
29
44
  }
30
45
 
31
- var fullPath = buildFullPath(config.baseURL, config.url);
46
+ var fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
47
+
32
48
  request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
33
49
 
34
50
  // Set the request timeout in MS
@@ -51,7 +67,13 @@ module.exports = function xhrAdapter(config) {
51
67
  request: request
52
68
  };
53
69
 
54
- settle(resolve, reject, response);
70
+ settle(function _resolve(value) {
71
+ resolve(value);
72
+ done();
73
+ }, function _reject(err) {
74
+ reject(err);
75
+ done();
76
+ }, response);
55
77
 
56
78
  // Clean up request
57
79
  request = null;
@@ -86,7 +108,7 @@ module.exports = function xhrAdapter(config) {
86
108
  return;
87
109
  }
88
110
 
89
- reject(createError('Request aborted', config, 'ECONNABORTED', request));
111
+ reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
90
112
 
91
113
  // Clean up request
92
114
  request = null;
@@ -96,7 +118,7 @@ module.exports = function xhrAdapter(config) {
96
118
  request.onerror = function handleError() {
97
119
  // Real errors are hidden from us by the browser
98
120
  // onerror should only fire if it's a network error
99
- reject(createError('Network Error', config, null, request));
121
+ reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
100
122
 
101
123
  // Clean up request
102
124
  request = null;
@@ -104,14 +126,15 @@ module.exports = function xhrAdapter(config) {
104
126
 
105
127
  // Handle timeout
106
128
  request.ontimeout = function handleTimeout() {
107
- var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
129
+ var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
130
+ var transitional = config.transitional || transitionalDefaults;
108
131
  if (config.timeoutErrorMessage) {
109
132
  timeoutErrorMessage = config.timeoutErrorMessage;
110
133
  }
111
- reject(createError(
134
+ reject(new AxiosError(
112
135
  timeoutErrorMessage,
136
+ transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
113
137
  config,
114
- config.transitional && config.transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
115
138
  request));
116
139
 
117
140
  // Clean up request
@@ -123,12 +146,13 @@ module.exports = function xhrAdapter(config) {
123
146
  // Specifically not if we're in a web worker, or react-native.
124
147
  if (utils.isStandardBrowserEnv()) {
125
148
  // Add xsrf header
126
- var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
127
- cookies.read(config.xsrfCookieName) :
128
- undefined;
129
-
130
- if (xsrfValue) {
131
- requestHeaders[config.xsrfHeaderName] = xsrfValue;
149
+ withXSRFToken && utils.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(config));
150
+ if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(fullPath))) {
151
+ // Add xsrf header
152
+ var xsrfValue = config.xsrfHeaderName && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
153
+ if (xsrfValue) {
154
+ requestHeaders[config.xsrfHeaderName] = xsrfValue;
155
+ }
132
156
  }
133
157
  }
134
158
 
@@ -165,24 +189,37 @@ module.exports = function xhrAdapter(config) {
165
189
  request.upload.addEventListener('progress', config.onUploadProgress);
166
190
  }
167
191
 
168
- if (config.cancelToken) {
192
+ if (config.cancelToken || config.signal) {
169
193
  // Handle cancellation
170
- config.cancelToken.promise.then(function onCanceled(cancel) {
194
+ // eslint-disable-next-line func-names
195
+ onCanceled = function(cancel) {
171
196
  if (!request) {
172
197
  return;
173
198
  }
174
-
199
+ reject(!cancel || cancel.type ? new CanceledError(null, config, request) : cancel);
175
200
  request.abort();
176
- reject(cancel);
177
- // Clean up request
178
201
  request = null;
179
- });
202
+ };
203
+
204
+ config.cancelToken && config.cancelToken.subscribe(onCanceled);
205
+ if (config.signal) {
206
+ config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
207
+ }
180
208
  }
181
209
 
182
- if (!requestData) {
210
+ // false, 0 (zero number), and '' (empty string) are valid JSON values
211
+ if (!requestData && requestData !== false && requestData !== 0 && requestData !== '') {
183
212
  requestData = null;
184
213
  }
185
214
 
215
+ var protocol = parseProtocol(fullPath);
216
+
217
+ if (protocol && platform.protocols.indexOf(protocol) === -1) {
218
+ reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
219
+ return;
220
+ }
221
+
222
+
186
223
  // Send the request
187
224
  request.send(requestData);
188
225
  });
package/lib/axios.js CHANGED
@@ -5,7 +5,7 @@ var bind = require('./helpers/bind');
5
5
  var Axios = require('./core/Axios');
6
6
  var mergeConfig = require('./core/mergeConfig');
7
7
  var defaults = require('./defaults');
8
-
8
+ var formDataToJSON = require('./helpers/formDataToJSON');
9
9
  /**
10
10
  * Create an instance of Axios
11
11
  *
@@ -22,6 +22,11 @@ function createInstance(defaultConfig) {
22
22
  // Copy context to instance
23
23
  utils.extend(instance, context);
24
24
 
25
+ // Factory for creating new instances
26
+ instance.create = function create(instanceConfig) {
27
+ return createInstance(mergeConfig(defaultConfig, instanceConfig));
28
+ };
29
+
25
30
  return instance;
26
31
  }
27
32
 
@@ -31,15 +36,18 @@ var axios = createInstance(defaults);
31
36
  // Expose Axios class to allow class inheritance
32
37
  axios.Axios = Axios;
33
38
 
34
- // Factory for creating new instances
35
- axios.create = function create(instanceConfig) {
36
- return createInstance(mergeConfig(axios.defaults, instanceConfig));
37
- };
38
-
39
39
  // Expose Cancel & CancelToken
40
- axios.Cancel = require('./cancel/Cancel');
40
+ axios.CanceledError = require('./cancel/CanceledError');
41
41
  axios.CancelToken = require('./cancel/CancelToken');
42
42
  axios.isCancel = require('./cancel/isCancel');
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;
43
51
 
44
52
  // Expose all/spread
45
53
  axios.all = function all(promises) {
@@ -50,6 +58,10 @@ axios.spread = require('./helpers/spread');
50
58
  // Expose isAxiosError
51
59
  axios.isAxiosError = require('./helpers/isAxiosError');
52
60
 
61
+ axios.formToJSON = function(thing) {
62
+ return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
63
+ };
64
+
53
65
  module.exports = axios;
54
66
 
55
67
  // Allow use of default import syntax in TypeScript
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Cancel = require('./Cancel');
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.
@@ -14,24 +14,54 @@ function CancelToken(executor) {
14
14
  }
15
15
 
16
16
  var resolvePromise;
17
+
17
18
  this.promise = new Promise(function promiseExecutor(resolve) {
18
19
  resolvePromise = resolve;
19
20
  });
20
21
 
21
22
  var token = this;
22
- executor(function cancel(message) {
23
+
24
+ // eslint-disable-next-line func-names
25
+ this.promise.then(function(cancel) {
26
+ if (!token._listeners) return;
27
+
28
+ var i = token._listeners.length;
29
+
30
+ while (i-- > 0) {
31
+ token._listeners[i](cancel);
32
+ }
33
+ token._listeners = null;
34
+ });
35
+
36
+ // eslint-disable-next-line func-names
37
+ this.promise.then = function(onfulfilled) {
38
+ var _resolve;
39
+ // eslint-disable-next-line func-names
40
+ var promise = new Promise(function(resolve) {
41
+ token.subscribe(resolve);
42
+ _resolve = resolve;
43
+ }).then(onfulfilled);
44
+
45
+ promise.cancel = function reject() {
46
+ token.unsubscribe(_resolve);
47
+ };
48
+
49
+ return promise;
50
+ };
51
+
52
+ executor(function cancel(message, config, request) {
23
53
  if (token.reason) {
24
54
  // Cancellation has already been requested
25
55
  return;
26
56
  }
27
57
 
28
- token.reason = new Cancel(message);
58
+ token.reason = new CanceledError(message, config, request);
29
59
  resolvePromise(token.reason);
30
60
  });
31
61
  }
32
62
 
33
63
  /**
34
- * Throws a `Cancel` if cancellation has been requested.
64
+ * Throws a `CanceledError` if cancellation has been requested.
35
65
  */
36
66
  CancelToken.prototype.throwIfRequested = function throwIfRequested() {
37
67
  if (this.reason) {
@@ -39,6 +69,37 @@ CancelToken.prototype.throwIfRequested = function throwIfRequested() {
39
69
  }
40
70
  };
41
71
 
72
+ /**
73
+ * Subscribe to the cancel signal
74
+ */
75
+
76
+ CancelToken.prototype.subscribe = function subscribe(listener) {
77
+ if (this.reason) {
78
+ listener(this.reason);
79
+ return;
80
+ }
81
+
82
+ if (this._listeners) {
83
+ this._listeners.push(listener);
84
+ } else {
85
+ this._listeners = [listener];
86
+ }
87
+ };
88
+
89
+ /**
90
+ * Unsubscribe from the cancel signal
91
+ */
92
+
93
+ CancelToken.prototype.unsubscribe = function unsubscribe(listener) {
94
+ if (!this._listeners) {
95
+ return;
96
+ }
97
+ var index = this._listeners.indexOf(listener);
98
+ if (index !== -1) {
99
+ this._listeners.splice(index, 1);
100
+ }
101
+ };
102
+
42
103
  /**
43
104
  * Returns an object that contains a new `CancelToken` and a function that, when called,
44
105
  * cancels the `CancelToken`.
@@ -0,0 +1,24 @@
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
+ * @param {Object=} config The config.
12
+ * @param {Object=} request The request.
13
+ */
14
+ function CanceledError(message, config, request) {
15
+ // eslint-disable-next-line no-eq-null,eqeqeq
16
+ AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
17
+ this.name = 'CanceledError';
18
+ }
19
+
20
+ utils.inherits(CanceledError, AxiosError, {
21
+ __CANCEL__: true
22
+ });
23
+
24
+ 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;
@@ -24,16 +25,17 @@ function Axios(instanceConfig) {
24
25
  /**
25
26
  * Dispatch a request
26
27
  *
27
- * @param {Object} config The config specific for this request (merged with this.defaults)
28
+ * @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
29
+ * @param {?Object} config
28
30
  */
29
- Axios.prototype.request = function request(config) {
31
+ Axios.prototype.request = function request(configOrUrl, config) {
30
32
  /*eslint no-param-reassign:0*/
31
33
  // Allow for axios('example/url'[, config]) a la fetch API
32
- if (typeof config === 'string') {
33
- config = arguments[1] || {};
34
- config.url = arguments[0];
35
- } else {
34
+ if (typeof configOrUrl === 'string') {
36
35
  config = config || {};
36
+ config.url = configOrUrl;
37
+ } else {
38
+ config = configOrUrl || {};
37
39
  }
38
40
 
39
41
  config = mergeConfig(this.defaults, config);
@@ -51,12 +53,27 @@ Axios.prototype.request = function request(config) {
51
53
 
52
54
  if (transitional !== undefined) {
53
55
  validator.assertOptions(transitional, {
54
- silentJSONParsing: validators.transitional(validators.boolean, '1.0.0'),
55
- forcedJSONParsing: validators.transitional(validators.boolean, '1.0.0'),
56
- clarifyTimeoutError: validators.transitional(validators.boolean, '1.0.0')
56
+ silentJSONParsing: validators.transitional(validators.boolean),
57
+ forcedJSONParsing: validators.transitional(validators.boolean),
58
+ clarifyTimeoutError: validators.transitional(validators.boolean)
57
59
  }, false);
58
60
  }
59
61
 
62
+ var paramsSerializer = config.paramsSerializer;
63
+
64
+ if (paramsSerializer != null) {
65
+ if (utils.isFunction(paramsSerializer)) {
66
+ config.paramsSerializer = {
67
+ serialize: paramsSerializer
68
+ };
69
+ } else {
70
+ validator.assertOptions(paramsSerializer, {
71
+ encode: validators.function,
72
+ serialize: validators.function
73
+ }, true);
74
+ }
75
+ }
76
+
60
77
  // filter out skipped interceptors
61
78
  var requestInterceptorChain = [];
62
79
  var synchronousRequestInterceptors = true;
@@ -119,7 +136,8 @@ Axios.prototype.request = function request(config) {
119
136
 
120
137
  Axios.prototype.getUri = function getUri(config) {
121
138
  config = mergeConfig(this.defaults, config);
122
- return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
139
+ var fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
140
+ return buildURL(fullPath, config.params, config.paramsSerializer);
123
141
  };
124
142
 
125
143
  // Provide aliases for supported request methods
@@ -136,13 +154,23 @@ utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData
136
154
 
137
155
  utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
138
156
  /*eslint func-names:0*/
139
- Axios.prototype[method] = function(url, data, config) {
140
- return this.request(mergeConfig(config || {}, {
141
- method: method,
142
- url: url,
143
- data: data
144
- }));
145
- };
157
+
158
+ function generateHTTPMethod(isForm) {
159
+ return function httpMethod(url, data, config) {
160
+ return this.request(mergeConfig(config || {}, {
161
+ method: method,
162
+ headers: isForm ? {
163
+ 'Content-Type': 'multipart/form-data'
164
+ } : {},
165
+ url: url,
166
+ data: data
167
+ }));
168
+ };
169
+ }
170
+
171
+ Axios.prototype[method] = generateHTTPMethod();
172
+
173
+ Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
146
174
  });
147
175
 
148
176
  module.exports = Axios;
@@ -0,0 +1,97 @@
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
+
18
+ if (Error.captureStackTrace) {
19
+ Error.captureStackTrace(this, this.constructor);
20
+ } else {
21
+ this.stack = (new Error()).stack;
22
+ }
23
+
24
+ this.message = message;
25
+ this.name = 'AxiosError';
26
+ code && (this.code = code);
27
+ config && (this.config = config);
28
+ request && (this.request = request);
29
+ response && (this.response = response);
30
+ }
31
+
32
+ utils.inherits(AxiosError, Error, {
33
+ toJSON: function toJSON() {
34
+ return {
35
+ // Standard
36
+ message: this.message,
37
+ name: this.name,
38
+ // Microsoft
39
+ description: this.description,
40
+ number: this.number,
41
+ // Mozilla
42
+ fileName: this.fileName,
43
+ lineNumber: this.lineNumber,
44
+ columnNumber: this.columnNumber,
45
+ stack: this.stack,
46
+ // Axios
47
+ config: this.config,
48
+ code: this.code,
49
+ status: this.response && this.response.status ? this.response.status : null
50
+ };
51
+ }
52
+ });
53
+
54
+ var prototype = AxiosError.prototype;
55
+ var descriptors = {};
56
+
57
+ [
58
+ 'ERR_BAD_OPTION_VALUE',
59
+ 'ERR_BAD_OPTION',
60
+ 'ECONNABORTED',
61
+ 'ETIMEDOUT',
62
+ 'ERR_NETWORK',
63
+ 'ERR_FR_TOO_MANY_REDIRECTS',
64
+ 'ERR_DEPRECATED',
65
+ 'ERR_BAD_RESPONSE',
66
+ 'ERR_BAD_REQUEST',
67
+ 'ERR_CANCELED',
68
+ 'ERR_NOT_SUPPORT',
69
+ 'ERR_INVALID_URL'
70
+ // eslint-disable-next-line func-names
71
+ ].forEach(function(code) {
72
+ descriptors[code] = {value: code};
73
+ });
74
+
75
+ Object.defineProperties(AxiosError, descriptors);
76
+ Object.defineProperty(prototype, 'isAxiosError', {value: true});
77
+
78
+ // eslint-disable-next-line func-names
79
+ AxiosError.from = function(error, code, config, request, response, customProps) {
80
+ var axiosError = Object.create(prototype);
81
+
82
+ utils.toFlatObject(error, axiosError, function filter(obj) {
83
+ return obj !== Error.prototype;
84
+ });
85
+
86
+ AxiosError.call(axiosError, error.message, code, config, request, response);
87
+
88
+ axiosError.cause = error;
89
+
90
+ axiosError.name = error.name;
91
+
92
+ customProps && Object.assign(axiosError, customProps);
93
+
94
+ return axiosError;
95
+ };
96
+
97
+ module.exports = AxiosError;
@@ -35,6 +35,15 @@ InterceptorManager.prototype.eject = function eject(id) {
35
35
  }
36
36
  };
37
37
 
38
+ /**
39
+ * Clear all interceptors from the stack
40
+ */
41
+ InterceptorManager.prototype.clear = function clear() {
42
+ if (this.handlers) {
43
+ this.handlers = [];
44
+ }
45
+ };
46
+
38
47
  /**
39
48
  * Iterate over all the registered interceptors
40
49
  *
@@ -10,10 +10,13 @@ var combineURLs = require('../helpers/combineURLs');
10
10
  *
11
11
  * @param {string} baseURL The base URL
12
12
  * @param {string} requestedURL Absolute or relative URL to combine
13
+ * @param {boolean} allowAbsoluteUrls Set to true to allow absolute URLs
14
+ *
13
15
  * @returns {string} The combined full path
14
16
  */
15
- module.exports = function buildFullPath(baseURL, requestedURL) {
16
- if (baseURL && !isAbsoluteURL(requestedURL)) {
17
+ module.exports = function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
18
+ var isRelativeURL = !isAbsoluteURL(requestedURL);
19
+ if (baseURL && (isRelativeURL || allowAbsoluteUrls === false)) {
17
20
  return combineURLs(baseURL, requestedURL);
18
21
  }
19
22
  return requestedURL;
@@ -4,14 +4,20 @@ 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 CanceledError = require('../cancel/CanceledError');
8
+ var normalizeHeaderName = require('../helpers/normalizeHeaderName');
7
9
 
8
10
  /**
9
- * Throws a `Cancel` if cancellation has been requested.
11
+ * Throws a `CanceledError` if cancellation has been requested.
10
12
  */
11
13
  function throwIfCancellationRequested(config) {
12
14
  if (config.cancelToken) {
13
15
  config.cancelToken.throwIfRequested();
14
16
  }
17
+
18
+ if (config.signal && config.signal.aborted) {
19
+ throw new CanceledError();
20
+ }
15
21
  }
16
22
 
17
23
  /**
@@ -31,9 +37,13 @@ module.exports = function dispatchRequest(config) {
31
37
  config,
32
38
  config.data,
33
39
  config.headers,
40
+ null,
34
41
  config.transformRequest
35
42
  );
36
43
 
44
+ normalizeHeaderName(config.headers, 'Accept');
45
+ normalizeHeaderName(config.headers, 'Content-Type');
46
+
37
47
  // Flatten headers
38
48
  config.headers = utils.merge(
39
49
  config.headers.common || {},
@@ -58,6 +68,7 @@ module.exports = function dispatchRequest(config) {
58
68
  config,
59
69
  response.data,
60
70
  response.headers,
71
+ response.status,
61
72
  config.transformResponse
62
73
  );
63
74
 
@@ -72,6 +83,7 @@ module.exports = function dispatchRequest(config) {
72
83
  config,
73
84
  reason.response.data,
74
85
  reason.response.headers,
86
+ reason.response.status,
75
87
  config.transformResponse
76
88
  );
77
89
  }