axios 0.26.0 → 0.27.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.
package/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  // TypeScript Version: 3.0
2
-
3
2
  export type AxiosRequestHeaders = Record<string, string | number | boolean>;
4
3
 
5
4
  export type AxiosResponseHeaders = Record<string, string> & {
@@ -75,7 +74,7 @@ export interface TransitionalOptions {
75
74
 
76
75
  export interface AxiosRequestConfig<D = any> {
77
76
  url?: string;
78
- method?: Method;
77
+ method?: Method | string;
79
78
  baseURL?: string;
80
79
  transformRequest?: AxiosRequestTransformer | AxiosRequestTransformer[];
81
80
  transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
@@ -98,6 +97,7 @@ export interface AxiosRequestConfig<D = any> {
98
97
  validateStatus?: ((status: number) => boolean) | null;
99
98
  maxBodyLength?: number;
100
99
  maxRedirects?: number;
100
+ beforeRedirect?: (options: Record<string, any>, responseDetails: {headers: Record<string, string>}) => void;
101
101
  socketPath?: string | null;
102
102
  httpAgent?: any;
103
103
  httpsAgent?: any;
@@ -107,6 +107,9 @@ export interface AxiosRequestConfig<D = any> {
107
107
  transitional?: TransitionalOptions;
108
108
  signal?: AbortSignal;
109
109
  insecureHTTPParser?: boolean;
110
+ env?: {
111
+ FormData?: new (...args: any[]) => object;
112
+ };
110
113
  }
111
114
 
112
115
  export interface HeadersDefaults {
@@ -136,13 +139,35 @@ export interface AxiosResponse<T = any, D = any> {
136
139
  request?: any;
137
140
  }
138
141
 
139
- export interface AxiosError<T = any, D = any> extends Error {
142
+ export class AxiosError<T = unknown, D = any> extends Error {
143
+ constructor(
144
+ message?: string,
145
+ code?: string,
146
+ config?: AxiosRequestConfig<D>,
147
+ request?: any,
148
+ response?: AxiosResponse<T, D>
149
+ );
150
+
140
151
  config: AxiosRequestConfig<D>;
141
152
  code?: string;
142
153
  request?: any;
143
154
  response?: AxiosResponse<T, D>;
144
155
  isAxiosError: boolean;
156
+ status?: string;
145
157
  toJSON: () => object;
158
+ static readonly ERR_FR_TOO_MANY_REDIRECTS = "ERR_FR_TOO_MANY_REDIRECTS";
159
+ static readonly ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
160
+ static readonly ERR_BAD_OPTION = "ERR_BAD_OPTION";
161
+ static readonly ERR_NETWORK = "ERR_NETWORK";
162
+ static readonly ERR_DEPRECATED = "ERR_DEPRECATED";
163
+ static readonly ERR_BAD_RESPONSE = "ERR_BAD_RESPONSE";
164
+ static readonly ERR_BAD_REQUEST = "ERR_BAD_REQUEST";
165
+ static readonly ERR_CANCELED = "ERR_CANCELED";
166
+ static readonly ECONNABORTED = "ECONNABORTED";
167
+ static readonly ETIMEDOUT = "ETIMEDOUT";
168
+ }
169
+
170
+ export class CanceledError<T> extends AxiosError<T> {
146
171
  }
147
172
 
148
173
  export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
@@ -176,8 +201,13 @@ export interface CancelTokenSource {
176
201
  cancel: Canceler;
177
202
  }
178
203
 
204
+ export interface AxiosInterceptorOptions {
205
+ synchronous?: boolean;
206
+ runWhen?: (config: AxiosRequestConfig) => boolean;
207
+ }
208
+
179
209
  export interface AxiosInterceptorManager<V> {
180
- use<T = V>(onFulfilled?: (value: V) => T | Promise<T>, onRejected?: (error: any) => any): number;
210
+ use<T = V>(onFulfilled?: (value: V) => T | Promise<T>, onRejected?: (error: any) => any, options?: AxiosInterceptorOptions): number;
181
211
  eject(id: number): void;
182
212
  }
183
213
 
@@ -197,6 +227,9 @@ export class Axios {
197
227
  post<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
198
228
  put<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
199
229
  patch<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
230
+ postForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
231
+ putForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
232
+ patchForm<T = any, R = AxiosResponse<T>, D = any>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;
200
233
  }
201
234
 
202
235
  export interface AxiosInstance extends Axios {
@@ -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
- var defaults = require('../defaults');
17
- var Cancel = require('../cancel/Cancel');
14
+ var transitionalDefaults = require('../defaults/transitional');
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
- if (data && !utils.isStream(data)) {
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(createError(
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(createError('Request body larger than maxBodyLength limit', config));
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 || 'http:';
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(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
292
- config, null, lastRequest));
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(createError('error request aborted', config, 'ERR_REQUEST_ABORTED', lastRequest));
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(enhanceError(err, config, null, lastRequest));
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(enhanceError(err, config, err.code, response.request, response));
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
- if (req.aborted && err.code !== 'ERR_FR_TOO_MANY_REDIRECTS') return;
330
- reject(enhanceError(err, config, null, req));
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(createError(
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
- var transitional = config.transitional || defaults.transitional;
369
- reject(createError(
370
- timeoutErrorMessage,
388
+ var transitional = config.transitional || transitionalDefaults;
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 Cancel('canceled') : cancel);
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(enhanceError(err, config, null, req));
418
+ reject(AxiosError.from(err, config, null, req));
399
419
  }).pipe(req);
400
420
  } else {
401
421
  req.end(data);
@@ -7,9 +7,9 @@ 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
- var defaults = require('../defaults');
12
- var Cancel = require('../cancel/Cancel');
10
+ var transitionalDefaults = require('../defaults/transitional');
11
+ var AxiosError = require('../core/AxiosError');
12
+ var CanceledError = require('../cancel/CanceledError');
13
13
 
14
14
  module.exports = function xhrAdapter(config) {
15
15
  return new Promise(function dispatchXhrRequest(resolve, reject) {
@@ -27,10 +27,6 @@ module.exports = function xhrAdapter(config) {
27
27
  }
28
28
  }
29
29
 
30
- if (utils.isFormData(requestData)) {
31
- delete requestHeaders['Content-Type']; // Let the browser set it
32
- }
33
-
34
30
  var request = new XMLHttpRequest();
35
31
 
36
32
  // HTTP basic authentication
@@ -41,6 +37,7 @@ module.exports = function xhrAdapter(config) {
41
37
  }
42
38
 
43
39
  var fullPath = buildFullPath(config.baseURL, config.url);
40
+
44
41
  request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
45
42
 
46
43
  // Set the request timeout in MS
@@ -104,7 +101,7 @@ module.exports = function xhrAdapter(config) {
104
101
  return;
105
102
  }
106
103
 
107
- reject(createError('Request aborted', config, 'ECONNABORTED', request));
104
+ reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
108
105
 
109
106
  // Clean up request
110
107
  request = null;
@@ -114,7 +111,7 @@ module.exports = function xhrAdapter(config) {
114
111
  request.onerror = function handleError() {
115
112
  // Real errors are hidden from us by the browser
116
113
  // onerror should only fire if it's a network error
117
- reject(createError('Network Error', config, null, request));
114
+ reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request, request));
118
115
 
119
116
  // Clean up request
120
117
  request = null;
@@ -123,14 +120,14 @@ module.exports = function xhrAdapter(config) {
123
120
  // Handle timeout
124
121
  request.ontimeout = function handleTimeout() {
125
122
  var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
126
- var transitional = config.transitional || defaults.transitional;
123
+ var transitional = config.transitional || transitionalDefaults;
127
124
  if (config.timeoutErrorMessage) {
128
125
  timeoutErrorMessage = config.timeoutErrorMessage;
129
126
  }
130
- reject(createError(
127
+ reject(new AxiosError(
131
128
  timeoutErrorMessage,
129
+ transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
132
130
  config,
133
- transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
134
131
  request));
135
132
 
136
133
  // Clean up request
@@ -191,7 +188,7 @@ module.exports = function xhrAdapter(config) {
191
188
  if (!request) {
192
189
  return;
193
190
  }
194
- reject(!cancel || (cancel && cancel.type) ? new Cancel('canceled') : cancel);
191
+ reject(!cancel || (cancel && cancel.type) ? new CanceledError() : cancel);
195
192
  request.abort();
196
193
  request = null;
197
194
  };
@@ -206,6 +203,15 @@ module.exports = function xhrAdapter(config) {
206
203
  requestData = null;
207
204
  }
208
205
 
206
+ var tokens = fullPath.split(':', 2);
207
+ var protocol = tokens.length > 1 && tokens[0];
208
+
209
+ if (protocol && [ 'http', 'https', 'file' ].indexOf(protocol) === -1) {
210
+ reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
211
+ return;
212
+ }
213
+
214
+
209
215
  // Send the request
210
216
  request.send(requestData);
211
217
  });
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.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
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 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.
@@ -56,13 +56,13 @@ function CancelToken(executor) {
56
56
  return;
57
57
  }
58
58
 
59
- token.reason = new Cancel(message);
59
+ token.reason = new CanceledError(message);
60
60
  resolvePromise(token.reason);
61
61
  });
62
62
  }
63
63
 
64
64
  /**
65
- * Throws a `Cancel` if cancellation has been requested.
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
- return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
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
- Axios.prototype[method] = function(url, data, config) {
140
- return this.request(mergeConfig(config || {}, {
141
- method: method,
142
- url: url,
143
- data: data
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 Cancel = require('../cancel/Cancel');
7
+ var CanceledError = require('../cancel/CanceledError');
8
8
 
9
9
  /**
10
- * Throws a `Cancel` if cancellation has been requested.
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 Cancel('canceled');
18
+ throw new CanceledError();
19
19
  }
20
20
  }
21
21
 
@@ -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,
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var createError = require('./createError');
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(createError(
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
  ));
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var utils = require('./../utils');
4
- var defaults = require('./../defaults');
4
+ var defaults = require('../defaults');
5
5
 
6
6
  /**
7
7
  * Transform the data for a request or a response
@@ -0,0 +1,2 @@
1
+ // eslint-disable-next-line strict
2
+ module.exports = require('form-data');