axios 1.0.0-alpha.1 → 1.0.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.
Potentially problematic release.
This version of axios might be problematic. Click here for more details.
- package/CHANGELOG.md +55 -1
- package/README.md +59 -48
- package/SECURITY.md +3 -2
- package/bin/ssl_hotfix.js +1 -1
- package/dist/axios.js +1552 -975
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/esm/axios.js +1471 -865
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +3750 -0
- package/dist/node/axios.cjs.map +1 -0
- package/gulpfile.js +88 -0
- package/index.d.ts +208 -63
- package/index.js +2 -1
- package/karma.conf.cjs +250 -0
- package/lib/adapters/http.js +251 -131
- package/lib/adapters/index.js +33 -0
- package/lib/adapters/xhr.js +79 -56
- package/lib/axios.js +33 -25
- package/lib/cancel/CancelToken.js +91 -88
- package/lib/cancel/CanceledError.js +5 -4
- package/lib/cancel/isCancel.js +2 -2
- package/lib/core/Axios.js +127 -100
- package/lib/core/AxiosError.js +10 -7
- package/lib/core/AxiosHeaders.js +274 -0
- package/lib/core/InterceptorManager.js +61 -53
- package/lib/core/buildFullPath.js +5 -4
- package/lib/core/dispatchRequest.js +21 -39
- package/lib/core/mergeConfig.js +8 -7
- package/lib/core/settle.js +6 -4
- package/lib/core/transformData.js +15 -10
- package/lib/defaults/index.js +46 -39
- package/lib/defaults/transitional.js +1 -1
- package/lib/env/classes/FormData.js +2 -2
- package/lib/env/data.js +1 -3
- package/lib/helpers/AxiosTransformStream.js +191 -0
- package/lib/helpers/AxiosURLSearchParams.js +23 -7
- package/lib/helpers/bind.js +2 -2
- package/lib/helpers/buildURL.js +16 -7
- package/lib/helpers/combineURLs.js +3 -2
- package/lib/helpers/cookies.js +43 -44
- package/lib/helpers/deprecatedMethod.js +4 -2
- package/lib/helpers/formDataToJSON.js +36 -15
- package/lib/helpers/fromDataURI.js +15 -13
- package/lib/helpers/isAbsoluteURL.js +3 -2
- package/lib/helpers/isAxiosError.js +4 -3
- package/lib/helpers/isURLSameOrigin.js +55 -56
- package/lib/helpers/null.js +1 -1
- package/lib/helpers/parseHeaders.js +24 -22
- package/lib/helpers/parseProtocol.js +3 -3
- package/lib/helpers/speedometer.js +55 -0
- package/lib/helpers/spread.js +3 -2
- package/lib/helpers/throttle.js +33 -0
- package/lib/helpers/toFormData.js +68 -18
- package/lib/helpers/toURLEncodedForm.js +5 -5
- package/lib/helpers/validator.js +20 -15
- package/lib/platform/browser/classes/FormData.js +1 -1
- package/lib/platform/browser/classes/URLSearchParams.js +2 -3
- package/lib/platform/browser/index.js +38 -6
- package/lib/platform/index.js +2 -2
- package/lib/platform/node/classes/FormData.js +2 -2
- package/lib/platform/node/classes/URLSearchParams.js +2 -3
- package/lib/platform/node/index.js +5 -4
- package/lib/utils.js +293 -191
- package/package.json +55 -22
- package/rollup.config.js +36 -6
- package/lib/helpers/normalizeHeaderName.js +0 -12
package/lib/adapters/xhr.js
CHANGED
@@ -1,24 +1,53 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
3
|
+
import utils from './../utils.js';
|
4
|
+
import settle from './../core/settle.js';
|
5
|
+
import cookies from './../helpers/cookies.js';
|
6
|
+
import buildURL from './../helpers/buildURL.js';
|
7
|
+
import buildFullPath from '../core/buildFullPath.js';
|
8
|
+
import isURLSameOrigin from './../helpers/isURLSameOrigin.js';
|
9
|
+
import transitionalDefaults from '../defaults/transitional.js';
|
10
|
+
import AxiosError from '../core/AxiosError.js';
|
11
|
+
import CanceledError from '../cancel/CanceledError.js';
|
12
|
+
import parseProtocol from '../helpers/parseProtocol.js';
|
13
|
+
import platform from '../platform/index.js';
|
14
|
+
import AxiosHeaders from '../core/AxiosHeaders.js';
|
15
|
+
import speedometer from '../helpers/speedometer.js';
|
16
|
+
|
17
|
+
function progressEventReducer(listener, isDownloadStream) {
|
18
|
+
let bytesNotified = 0;
|
19
|
+
const _speedometer = speedometer(50, 250);
|
20
|
+
|
21
|
+
return e => {
|
22
|
+
const loaded = e.loaded;
|
23
|
+
const total = e.lengthComputable ? e.total : undefined;
|
24
|
+
const progressBytes = loaded - bytesNotified;
|
25
|
+
const rate = _speedometer(progressBytes);
|
26
|
+
const inRange = loaded <= total;
|
27
|
+
|
28
|
+
bytesNotified = loaded;
|
29
|
+
|
30
|
+
const data = {
|
31
|
+
loaded,
|
32
|
+
total,
|
33
|
+
progress: total ? (loaded / total) : undefined,
|
34
|
+
bytes: progressBytes,
|
35
|
+
rate: rate ? rate : undefined,
|
36
|
+
estimated: rate && total && inRange ? (total - loaded) / rate : undefined
|
37
|
+
};
|
38
|
+
|
39
|
+
data[isDownloadStream ? 'download' : 'upload'] = true;
|
40
|
+
|
41
|
+
listener(data);
|
42
|
+
};
|
43
|
+
}
|
44
|
+
|
45
|
+
export default function xhrAdapter(config) {
|
17
46
|
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
47
|
+
let requestData = config.data;
|
48
|
+
const requestHeaders = AxiosHeaders.from(config.headers).normalize();
|
49
|
+
const responseType = config.responseType;
|
50
|
+
let onCanceled;
|
22
51
|
function done() {
|
23
52
|
if (config.cancelToken) {
|
24
53
|
config.cancelToken.unsubscribe(onCanceled);
|
@@ -29,20 +58,20 @@ module.exports = function xhrAdapter(config) {
|
|
29
58
|
}
|
30
59
|
}
|
31
60
|
|
32
|
-
if (utils.isFormData(requestData) &&
|
33
|
-
|
61
|
+
if (utils.isFormData(requestData) && platform.isStandardBrowserEnv) {
|
62
|
+
requestHeaders.setContentType(false); // Let the browser set it
|
34
63
|
}
|
35
64
|
|
36
|
-
|
65
|
+
let request = new XMLHttpRequest();
|
37
66
|
|
38
67
|
// HTTP basic authentication
|
39
68
|
if (config.auth) {
|
40
|
-
|
41
|
-
|
42
|
-
requestHeaders.Authorization
|
69
|
+
const username = config.auth.username || '';
|
70
|
+
const password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
71
|
+
requestHeaders.set('Authorization', 'Basic ' + btoa(username + ':' + password));
|
43
72
|
}
|
44
73
|
|
45
|
-
|
74
|
+
const fullPath = buildFullPath(config.baseURL, config.url);
|
46
75
|
|
47
76
|
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
48
77
|
|
@@ -54,16 +83,18 @@ module.exports = function xhrAdapter(config) {
|
|
54
83
|
return;
|
55
84
|
}
|
56
85
|
// Prepare the response
|
57
|
-
|
58
|
-
|
86
|
+
const responseHeaders = AxiosHeaders.from(
|
87
|
+
'getAllResponseHeaders' in request && request.getAllResponseHeaders()
|
88
|
+
);
|
89
|
+
const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
|
59
90
|
request.responseText : request.response;
|
60
|
-
|
91
|
+
const response = {
|
61
92
|
data: responseData,
|
62
93
|
status: request.status,
|
63
94
|
statusText: request.statusText,
|
64
95
|
headers: responseHeaders,
|
65
|
-
config
|
66
|
-
request
|
96
|
+
config,
|
97
|
+
request
|
67
98
|
};
|
68
99
|
|
69
100
|
settle(function _resolve(value) {
|
@@ -125,8 +156,8 @@ module.exports = function xhrAdapter(config) {
|
|
125
156
|
|
126
157
|
// Handle timeout
|
127
158
|
request.ontimeout = function handleTimeout() {
|
128
|
-
|
129
|
-
|
159
|
+
let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
|
160
|
+
const transitional = config.transitional || transitionalDefaults;
|
130
161
|
if (config.timeoutErrorMessage) {
|
131
162
|
timeoutErrorMessage = config.timeoutErrorMessage;
|
132
163
|
}
|
@@ -143,27 +174,23 @@ module.exports = function xhrAdapter(config) {
|
|
143
174
|
// Add xsrf header
|
144
175
|
// This is only done if running in a standard browser environment.
|
145
176
|
// Specifically not if we're in a web worker, or react-native.
|
146
|
-
if (
|
177
|
+
if (platform.isStandardBrowserEnv) {
|
147
178
|
// Add xsrf header
|
148
|
-
|
149
|
-
cookies.read(config.xsrfCookieName)
|
150
|
-
undefined;
|
179
|
+
const xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath))
|
180
|
+
&& config.xsrfCookieName && cookies.read(config.xsrfCookieName);
|
151
181
|
|
152
182
|
if (xsrfValue) {
|
153
|
-
requestHeaders
|
183
|
+
requestHeaders.set(config.xsrfHeaderName, xsrfValue);
|
154
184
|
}
|
155
185
|
}
|
156
186
|
|
187
|
+
// Remove Content-Type if data is undefined
|
188
|
+
requestData === undefined && requestHeaders.setContentType(null);
|
189
|
+
|
157
190
|
// Add headers to the request
|
158
191
|
if ('setRequestHeader' in request) {
|
159
|
-
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
|
160
|
-
|
161
|
-
// Remove Content-Type if data is undefined
|
162
|
-
delete requestHeaders[key];
|
163
|
-
} else {
|
164
|
-
// Otherwise add header to the request
|
165
|
-
request.setRequestHeader(key, val);
|
166
|
-
}
|
192
|
+
utils.forEach(requestHeaders.toJSON(), function setRequestHeader(val, key) {
|
193
|
+
request.setRequestHeader(key, val);
|
167
194
|
});
|
168
195
|
}
|
169
196
|
|
@@ -179,22 +206,22 @@ module.exports = function xhrAdapter(config) {
|
|
179
206
|
|
180
207
|
// Handle progress if needed
|
181
208
|
if (typeof config.onDownloadProgress === 'function') {
|
182
|
-
request.addEventListener('progress', config.onDownloadProgress);
|
209
|
+
request.addEventListener('progress', progressEventReducer(config.onDownloadProgress, true));
|
183
210
|
}
|
184
211
|
|
185
212
|
// Not all browsers support upload events
|
186
213
|
if (typeof config.onUploadProgress === 'function' && request.upload) {
|
187
|
-
request.upload.addEventListener('progress', config.onUploadProgress);
|
214
|
+
request.upload.addEventListener('progress', progressEventReducer(config.onUploadProgress));
|
188
215
|
}
|
189
216
|
|
190
217
|
if (config.cancelToken || config.signal) {
|
191
218
|
// Handle cancellation
|
192
219
|
// eslint-disable-next-line func-names
|
193
|
-
onCanceled =
|
220
|
+
onCanceled = cancel => {
|
194
221
|
if (!request) {
|
195
222
|
return;
|
196
223
|
}
|
197
|
-
reject(!cancel || cancel.type ? new CanceledError(null, config,
|
224
|
+
reject(!cancel || cancel.type ? new CanceledError(null, config, request) : cancel);
|
198
225
|
request.abort();
|
199
226
|
request = null;
|
200
227
|
};
|
@@ -205,11 +232,7 @@ module.exports = function xhrAdapter(config) {
|
|
205
232
|
}
|
206
233
|
}
|
207
234
|
|
208
|
-
|
209
|
-
requestData = null;
|
210
|
-
}
|
211
|
-
|
212
|
-
var protocol = parseProtocol(fullPath);
|
235
|
+
const protocol = parseProtocol(fullPath);
|
213
236
|
|
214
237
|
if (protocol && platform.protocols.indexOf(protocol) === -1) {
|
215
238
|
reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
|
@@ -218,6 +241,6 @@ module.exports = function xhrAdapter(config) {
|
|
218
241
|
|
219
242
|
|
220
243
|
// Send the request
|
221
|
-
request.send(requestData);
|
244
|
+
request.send(requestData || null);
|
222
245
|
});
|
223
|
-
}
|
246
|
+
}
|
package/lib/axios.js
CHANGED
@@ -1,26 +1,36 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
import utils from './utils.js';
|
4
|
+
import bind from './helpers/bind.js';
|
5
|
+
import Axios from './core/Axios.js';
|
6
|
+
import mergeConfig from './core/mergeConfig.js';
|
7
|
+
import defaults from './defaults/index.js';
|
8
|
+
import formDataToJSON from './helpers/formDataToJSON.js';
|
9
|
+
import CanceledError from './cancel/CanceledError.js';
|
10
|
+
import CancelToken from'./cancel/CancelToken.js';
|
11
|
+
import isCancel from'./cancel/isCancel.js';
|
12
|
+
import {VERSION} from './env/data.js';
|
13
|
+
import toFormData from './helpers/toFormData.js';
|
14
|
+
import AxiosError from './core/AxiosError.js';
|
15
|
+
import spread from './helpers/spread.js';
|
16
|
+
import isAxiosError from './helpers/isAxiosError.js';
|
17
|
+
|
9
18
|
/**
|
10
19
|
* Create an instance of Axios
|
11
20
|
*
|
12
21
|
* @param {Object} defaultConfig The default config for the instance
|
13
|
-
*
|
22
|
+
*
|
23
|
+
* @returns {Axios} A new instance of Axios
|
14
24
|
*/
|
15
25
|
function createInstance(defaultConfig) {
|
16
|
-
|
17
|
-
|
26
|
+
const context = new Axios(defaultConfig);
|
27
|
+
const instance = bind(Axios.prototype.request, context);
|
18
28
|
|
19
29
|
// Copy axios.prototype to instance
|
20
|
-
utils.extend(instance, Axios.prototype, context);
|
30
|
+
utils.extend(instance, Axios.prototype, context, {allOwnKeys: true});
|
21
31
|
|
22
32
|
// Copy context to instance
|
23
|
-
utils.extend(instance, context);
|
33
|
+
utils.extend(instance, context, null, {allOwnKeys: true});
|
24
34
|
|
25
35
|
// Factory for creating new instances
|
26
36
|
instance.create = function create(instanceConfig) {
|
@@ -31,20 +41,20 @@ function createInstance(defaultConfig) {
|
|
31
41
|
}
|
32
42
|
|
33
43
|
// Create the default instance to be exported
|
34
|
-
|
44
|
+
const axios = createInstance(defaults);
|
35
45
|
|
36
46
|
// Expose Axios class to allow class inheritance
|
37
47
|
axios.Axios = Axios;
|
38
48
|
|
39
49
|
// Expose Cancel & CancelToken
|
40
|
-
axios.CanceledError =
|
41
|
-
axios.CancelToken =
|
42
|
-
axios.isCancel =
|
43
|
-
axios.VERSION =
|
44
|
-
axios.toFormData =
|
50
|
+
axios.CanceledError = CanceledError;
|
51
|
+
axios.CancelToken = CancelToken;
|
52
|
+
axios.isCancel = isCancel;
|
53
|
+
axios.VERSION = VERSION;
|
54
|
+
axios.toFormData = toFormData;
|
45
55
|
|
46
56
|
// Expose AxiosError class
|
47
|
-
axios.AxiosError =
|
57
|
+
axios.AxiosError = AxiosError;
|
48
58
|
|
49
59
|
// alias for CanceledError for backward compatibility
|
50
60
|
axios.Cancel = axios.CanceledError;
|
@@ -53,16 +63,14 @@ axios.Cancel = axios.CanceledError;
|
|
53
63
|
axios.all = function all(promises) {
|
54
64
|
return Promise.all(promises);
|
55
65
|
};
|
56
|
-
|
66
|
+
|
67
|
+
axios.spread = spread;
|
57
68
|
|
58
69
|
// Expose isAxiosError
|
59
|
-
axios.isAxiosError =
|
70
|
+
axios.isAxiosError = isAxiosError;
|
60
71
|
|
61
|
-
axios.formToJSON =
|
72
|
+
axios.formToJSON = thing => {
|
62
73
|
return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
63
74
|
};
|
64
75
|
|
65
|
-
|
66
|
-
|
67
|
-
// Allow use of default import syntax in TypeScript
|
68
|
-
module.exports.default = axios;
|
76
|
+
export default axios;
|
@@ -1,118 +1,121 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
3
|
+
import CanceledError from './CanceledError.js';
|
4
4
|
|
5
5
|
/**
|
6
6
|
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
7
7
|
*
|
8
|
-
* @class
|
9
8
|
* @param {Function} executor The executor function.
|
9
|
+
*
|
10
|
+
* @returns {CancelToken}
|
10
11
|
*/
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
class CancelToken {
|
13
|
+
constructor(executor) {
|
14
|
+
if (typeof executor !== 'function') {
|
15
|
+
throw new TypeError('executor must be a function.');
|
16
|
+
}
|
15
17
|
|
16
|
-
|
18
|
+
let resolvePromise;
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
this.promise = new Promise(function promiseExecutor(resolve) {
|
21
|
+
resolvePromise = resolve;
|
22
|
+
});
|
21
23
|
|
22
|
-
|
24
|
+
const token = this;
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
// eslint-disable-next-line func-names
|
27
|
+
this.promise.then(cancel => {
|
28
|
+
if (!token._listeners) return;
|
27
29
|
|
28
|
-
|
30
|
+
let i = token._listeners.length;
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
while (i-- > 0) {
|
33
|
+
token._listeners[i](cancel);
|
34
|
+
}
|
35
|
+
token._listeners = null;
|
36
|
+
});
|
35
37
|
|
36
|
-
// eslint-disable-next-line func-names
|
37
|
-
this.promise.then = function(onfulfilled) {
|
38
|
-
var _resolve;
|
39
38
|
// eslint-disable-next-line func-names
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
39
|
+
this.promise.then = onfulfilled => {
|
40
|
+
let _resolve;
|
41
|
+
// eslint-disable-next-line func-names
|
42
|
+
const promise = new Promise(resolve => {
|
43
|
+
token.subscribe(resolve);
|
44
|
+
_resolve = resolve;
|
45
|
+
}).then(onfulfilled);
|
46
|
+
|
47
|
+
promise.cancel = function reject() {
|
48
|
+
token.unsubscribe(_resolve);
|
49
|
+
};
|
50
|
+
|
51
|
+
return promise;
|
47
52
|
};
|
48
53
|
|
49
|
-
|
50
|
-
|
54
|
+
executor(function cancel(message, config, request) {
|
55
|
+
if (token.reason) {
|
56
|
+
// Cancellation has already been requested
|
57
|
+
return;
|
58
|
+
}
|
51
59
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
}
|
57
|
-
|
58
|
-
token.reason = new CanceledError(message, config, request);
|
59
|
-
resolvePromise(token.reason);
|
60
|
-
});
|
61
|
-
}
|
60
|
+
token.reason = new CanceledError(message, config, request);
|
61
|
+
resolvePromise(token.reason);
|
62
|
+
});
|
63
|
+
}
|
62
64
|
|
63
|
-
/**
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
/**
|
66
|
+
* Throws a `CanceledError` if cancellation has been requested.
|
67
|
+
*/
|
68
|
+
throwIfRequested() {
|
69
|
+
if (this.reason) {
|
70
|
+
throw this.reason;
|
71
|
+
}
|
69
72
|
}
|
70
|
-
};
|
71
73
|
|
72
|
-
/**
|
73
|
-
|
74
|
-
|
74
|
+
/**
|
75
|
+
* Subscribe to the cancel signal
|
76
|
+
*/
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
subscribe(listener) {
|
79
|
+
if (this.reason) {
|
80
|
+
listener(this.reason);
|
81
|
+
return;
|
82
|
+
}
|
81
83
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
84
|
+
if (this._listeners) {
|
85
|
+
this._listeners.push(listener);
|
86
|
+
} else {
|
87
|
+
this._listeners = [listener];
|
88
|
+
}
|
86
89
|
}
|
87
|
-
};
|
88
90
|
|
89
|
-
/**
|
90
|
-
|
91
|
-
|
91
|
+
/**
|
92
|
+
* Unsubscribe from the cancel signal
|
93
|
+
*/
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
-
|
95
|
+
unsubscribe(listener) {
|
96
|
+
if (!this._listeners) {
|
97
|
+
return;
|
98
|
+
}
|
99
|
+
const index = this._listeners.indexOf(listener);
|
100
|
+
if (index !== -1) {
|
101
|
+
this._listeners.splice(index, 1);
|
102
|
+
}
|
96
103
|
}
|
97
|
-
|
98
|
-
|
99
|
-
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
107
|
+
* cancels the `CancelToken`.
|
108
|
+
*/
|
109
|
+
static source() {
|
110
|
+
let cancel;
|
111
|
+
const token = new CancelToken(function executor(c) {
|
112
|
+
cancel = c;
|
113
|
+
});
|
114
|
+
return {
|
115
|
+
token,
|
116
|
+
cancel
|
117
|
+
};
|
100
118
|
}
|
101
|
-
}
|
119
|
+
}
|
102
120
|
|
103
|
-
|
104
|
-
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
105
|
-
* cancels the `CancelToken`.
|
106
|
-
*/
|
107
|
-
CancelToken.source = function source() {
|
108
|
-
var cancel;
|
109
|
-
var token = new CancelToken(function executor(c) {
|
110
|
-
cancel = c;
|
111
|
-
});
|
112
|
-
return {
|
113
|
-
token: token,
|
114
|
-
cancel: cancel
|
115
|
-
};
|
116
|
-
};
|
117
|
-
|
118
|
-
module.exports = CancelToken;
|
121
|
+
export default CancelToken;
|
@@ -1,15 +1,16 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
import AxiosError from '../core/AxiosError.js';
|
4
|
+
import utils from '../utils.js';
|
5
5
|
|
6
6
|
/**
|
7
7
|
* A `CanceledError` is an object that is thrown when an operation is canceled.
|
8
8
|
*
|
9
|
-
* @class
|
10
9
|
* @param {string=} message The message.
|
11
10
|
* @param {Object=} config The config.
|
12
11
|
* @param {Object=} request The request.
|
12
|
+
*
|
13
|
+
* @returns {CanceledError} The created error.
|
13
14
|
*/
|
14
15
|
function CanceledError(message, config, request) {
|
15
16
|
// eslint-disable-next-line no-eq-null,eqeqeq
|
@@ -21,4 +22,4 @@ utils.inherits(CanceledError, AxiosError, {
|
|
21
22
|
__CANCEL__: true
|
22
23
|
});
|
23
24
|
|
24
|
-
|
25
|
+
export default CanceledError;
|
package/lib/cancel/isCancel.js
CHANGED