2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-08 17:22:34 +03:00

Mended merge conflicts

This commit is contained in:
Jay
2022-03-09 19:41:56 +02:00
29 changed files with 334 additions and 228 deletions
+16 -22
View File
@@ -11,10 +11,9 @@ var httpsFollow = require('follow-redirects').https;
var url = require('url');
var zlib = require('zlib');
var VERSION = require('./../env/data').version;
var createError = require('../core/createError');
var enhanceError = require('../core/enhanceError');
var defaults = require('../defaults');
var Cancel = require('../cancel/Cancel');
var AxiosError = require('../core/AxiosError');
var CanceledError = require('../cancel/CanceledError');
var isHttps = /https:?/;
@@ -95,8 +94,9 @@ module.exports = function httpAdapter(config) {
} else if (utils.isString(data)) {
data = Buffer.from(data, 'utf-8');
} else {
return reject(createError(
return reject(new AxiosError(
'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
AxiosError.ERR_BAD_REQUEST,
config
));
}
@@ -288,8 +288,8 @@ module.exports = function httpAdapter(config) {
// stream.destoy() emit aborted event before calling reject() on Node.js v16
rejected = true;
stream.destroy();
reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
config, null, lastRequest));
reject(new AxiosError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
AxiosError.ERR_BAD_RESPONSE, config, lastRequest));
}
});
@@ -303,7 +303,7 @@ module.exports = function httpAdapter(config) {
stream.on('error', function handleStreamError(err) {
if (req.aborted) return;
reject(enhanceError(err, config, null, lastRequest));
reject(AxiosError.from(err, null, config, lastRequest));
});
stream.on('end', function handleStreamEnd() {
@@ -326,8 +326,8 @@ module.exports = function httpAdapter(config) {
// Handle errors
req.on('error', function handleRequestError(err) {
if (req.aborted && err.code !== 'ERR_FR_TOO_MANY_REDIRECTS') return;
reject(enhanceError(err, config, null, req));
if (req.aborted && err.code !== AxiosError.ERR_FR_TOO_MANY_REDIRECTS) return;
reject(AxiosError.from(err, null, config, req));
});
// set tcp keep alive to prevent drop connection by peer
@@ -342,10 +342,10 @@ module.exports = function httpAdapter(config) {
var timeout = parseInt(config.timeout, 10);
if (isNaN(timeout)) {
reject(createError(
reject(new AxiosError(
'error trying to parse `config.timeout` to int',
AxiosError.ERR_BAD_OPTION_VALUE,
config,
'ERR_PARSE_TIMEOUT',
req
));
@@ -359,17 +359,11 @@ module.exports = function httpAdapter(config) {
// ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
req.setTimeout(timeout, function handleRequestTimeout() {
req.abort();
var timeoutErrorMessage = '';
if (config.timeoutErrorMessage) {
timeoutErrorMessage = config.timeoutErrorMessage;
} else {
timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
}
var transitional = config.transitional || defaults.transitional;
reject(createError(
timeoutErrorMessage,
reject(new AxiosError(
'timeout of ' + timeout + 'ms exceeded',
transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
config,
transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
req
));
});
@@ -382,7 +376,7 @@ module.exports = function httpAdapter(config) {
if (req.aborted) return;
req.abort();
reject(!cancel || (cancel && cancel.type) ? new Cancel('canceled') : cancel);
reject(!cancel || (cancel && cancel.type) ? new CanceledError() : cancel);
};
config.cancelToken && config.cancelToken.subscribe(onCanceled);
@@ -395,7 +389,7 @@ module.exports = function httpAdapter(config) {
// Send the request
if (utils.isStream(data)) {
data.on('error', function handleStreamError(err) {
reject(enhanceError(err, config, null, req));
reject(AxiosError.from(err, config, null, req));
}).pipe(req);
} else {
req.end(data);