2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-14 18:42:33 +03:00

Removed all old error classes

This commit is contained in:
Jay
2022-03-10 08:30:59 +02:00
parent 340ad9ec8c
commit 80387424e4
2 changed files with 19 additions and 13 deletions
+17 -10
View File
@@ -11,8 +11,6 @@ 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 AxiosError = require('../core/AxiosError');
var CanceledError = require('../cancel/CanceledError');
@@ -104,7 +102,11 @@ module.exports = function httpAdapter(config) {
}
if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
return reject(createError('Request body larger than maxBodyLength limit', config));
return reject(new AxiosError(
'Request body larger than maxBodyLength limit',
AxiosError.ERR_BAD_REQUEST,
config
));
}
// Add Content-Length header if data exists
@@ -126,12 +128,12 @@ module.exports = function httpAdapter(config) {
var parsed = url.parse(fullPath);
var protocol = utils.getProtocol(parsed.protocol);
if (parsed.path === null) {
return reject(createError('Malformed URL ' + fullPath, config));
}
if (!utils.supportedProtocols.includes(protocol)) {
return reject(createError('Unsupported protocol ' + protocol, config));
return reject(new AxiosError(
'Unsupported protocol ' + protocol,
AxiosError.ERR_BAD_REQUEST,
config
));
}
if (!auth && parsed.auth) {
@@ -311,7 +313,12 @@ module.exports = function httpAdapter(config) {
return;
}
stream.destroy();
reject(createError('error request aborted', config, 'ERR_REQUEST_ABORTED', lastRequest));
reject(new AxiosError(
'maxContentLength size of ' + config.maxContentLength + ' exceeded',
AxiosError.ERR_BAD_RESPONSE,
config,
lastRequest
));
});
stream.on('error', function handleStreamError(err) {
@@ -330,7 +337,7 @@ module.exports = function httpAdapter(config) {
}
response.data = responseData;
} catch (err) {
reject(enhanceError(err, config, err.code, response.request, response));
reject(AxiosError.from(err, null, config, response.request, response));
}
settle(resolve, reject, response);
});
+2 -3
View File
@@ -7,7 +7,6 @@ var buildURL = require('./../helpers/buildURL');
var buildFullPath = require('../core/buildFullPath');
var parseHeaders = require('./../helpers/parseHeaders');
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
var createError = require('../core/createError');//
var url = require('url');
var transitionalDefaults = require('../defaults/transitional');
var AxiosError = require('../core/AxiosError');
@@ -212,12 +211,12 @@ module.exports = function xhrAdapter(config) {
}
if (parsed.path === null) {
reject(createError('Malformed URL ' + fullPath, config));
reject(new AxiosError('Malformed URL ' + fullPath, AxiosError.ERR_BAD_REQUEST, config));
return;
}
if (!utils.supportedProtocols.includes(protocol)) {
reject(createError('Unsupported protocol ' + protocol, config));
reject(new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_BAD_REQUEST, config));
return;
}