mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +03:00
Improve error handling
This commit is contained in:
+3
-5
@@ -6,6 +6,7 @@ var transformData = require('./../core/transformData');
|
||||
var buildURL = require('./../helpers/buildURL');
|
||||
var parseHeaders = require('./../helpers/parseHeaders');
|
||||
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
||||
var createError = require('../core/createError');
|
||||
var btoa = (typeof window !== 'undefined' && window.btoa) || require('./../helpers/btoa');
|
||||
|
||||
module.exports = function xhrAdapter(resolve, reject, config) {
|
||||
@@ -82,7 +83,7 @@ module.exports = function xhrAdapter(resolve, reject, 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(new Error('Network Error'));
|
||||
reject(createError('Network Error', config));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
@@ -90,10 +91,7 @@ module.exports = function xhrAdapter(resolve, reject, config) {
|
||||
|
||||
// Handle timeout
|
||||
request.ontimeout = function handleTimeout() {
|
||||
var err = new Error('timeout of ' + config.timeout + 'ms exceeded');
|
||||
err.timeout = config.timeout;
|
||||
err.code = 'ECONNABORTED';
|
||||
reject(err);
|
||||
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED'));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
|
||||
Reference in New Issue
Block a user