Skip to content

Commit

Permalink
Set isAxiosError property on errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbsgilbs committed Jul 8, 2019
1 parent 0ecd872 commit 2e9eb29
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
},
Expand All @@ -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);
});
},
Expand All @@ -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);
});
},
Expand All @@ -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);
});
}
Expand Down
1 change: 1 addition & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
13 changes: 13 additions & 0 deletions test/basics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
1 change: 1 addition & 0 deletions test/network_error.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
});
Expand Down
1 change: 1 addition & 0 deletions test/timeout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
});
Expand Down

0 comments on commit 2e9eb29

Please sign in to comment.