diff --git a/src/index.js b/src/index.js index d55517b..0c8b71e 100644 --- a/src/index.js +++ b/src/index.js @@ -97,6 +97,7 @@ VERBS.concat('any').forEach(function(method) { reply(function(config) { var error = new Error('Network Error'); error.config = config; + error.isAxiosError = true; return Promise.reject(error); }); }, @@ -105,6 +106,7 @@ VERBS.concat('any').forEach(function(method) { replyOnce(function(config) { var error = new Error('Network Error'); error.config = config; + error.isAxiosError = true; return Promise.reject(error); }); }, @@ -114,6 +116,7 @@ VERBS.concat('any').forEach(function(method) { var error = new Error('timeout of ' + config.timeout + 'ms exceeded'); error.config = config; error.code = 'ECONNABORTED'; + error.isAxiosError = true; return Promise.reject(error); }); }, @@ -123,6 +126,7 @@ VERBS.concat('any').forEach(function(method) { var error = new Error('timeout of ' + config.timeout + 'ms exceeded'); error.config = config; error.code = 'ECONNABORTED'; + error.isAxiosError = true; return Promise.reject(error); }); } diff --git a/src/utils.js b/src/utils.js index 5420cc1..3f3c92c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -117,6 +117,7 @@ function createErrorResponse(message, config, response) { var error = new Error(message); error.config = config; error.response = response; + error.isAxiosError = true; return error; } diff --git a/test/basics.spec.js b/test/basics.spec.js index d1d6dfa..191e808 100644 --- a/test/basics.spec.js +++ b/test/basics.spec.js @@ -773,4 +773,17 @@ describe('MockAdapter basics', function() { expect(response.status).to.equal(201); }); }); + + it('sets isAxiosInstance property on errors', function() { + mock.onGet('/').reply(404); + + return instance + .get('/') + .then(function() { + expect(true).to.be.false; + }) + .catch(function(error) { + expect(error.response.status).to.equal(404); + }); + }); }); diff --git a/test/network_error.spec.js b/test/network_error.spec.js index c0465e7..6dfe914 100644 --- a/test/network_error.spec.js +++ b/test/network_error.spec.js @@ -23,6 +23,7 @@ describe('networkError spec', function() { expect(error.config).to.exist; expect(error.response).to.not.exist; expect(error.message).to.equal('Network Error'); + expect(error.isAxiosError).to.be.true; } ); }); diff --git a/test/timeout.spec.js b/test/timeout.spec.js index 3496e8c..217c121 100644 --- a/test/timeout.spec.js +++ b/test/timeout.spec.js @@ -25,6 +25,7 @@ describe('timeout spec', function() { expect(error.config).to.exist; expect(error.code).to.equal('ECONNABORTED'); expect(error.message).to.equal('timeout of 0ms exceeded'); + expect(error.isAxiosError).to.be.true; } ); });