2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-11 18:02:32 +03:00

Adding request to error objects when it is available

This commit is contained in:
Rubén Norte
2017-04-08 21:44:15 +02:00
parent e0d59eb29b
commit 22ce6db383
5 changed files with 16 additions and 10 deletions
+5 -4
View File
@@ -172,13 +172,14 @@ module.exports = function httpAdapter(config) {
// make sure the content length is not over the maxContentLength if specified
if (config.maxContentLength > -1 && Buffer.concat(responseBuffer).length > config.maxContentLength) {
reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded', config));
reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
config, null, lastRequest));
}
});
stream.on('error', function handleStreamError(err) {
if (aborted) return;
reject(enhanceError(err, config));
reject(enhanceError(err, config, null, lastRequest));
});
stream.on('end', function handleStreamEnd() {
@@ -196,14 +197,14 @@ module.exports = function httpAdapter(config) {
// Handle errors
req.on('error', function handleRequestError(err) {
if (aborted) return;
reject(enhanceError(err, config));
reject(enhanceError(err, config, null, req));
});
// Handle request timeout
if (config.timeout && !timer) {
timer = setTimeout(function handleRequestTimeout() {
req.abort();
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED'));
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED', req));
aborted = true;
}, config.timeout);
}
+3 -2
View File
@@ -84,7 +84,7 @@ module.exports = function xhrAdapter(config) {
request.onerror = function handleError() {
// Real errors are hidden from us by the browser
// onerror should only fire if it's a network error
reject(createError('Network Error', config));
reject(createError('Network Error', config, null, request));
// Clean up request
request = null;
@@ -92,7 +92,8 @@ module.exports = function xhrAdapter(config) {
// Handle timeout
request.ontimeout = function handleTimeout() {
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED'));
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED',
request));
// Clean up request
request = null;