Skip to content

Commit

Permalink
Handle timeoutErrorMessage if provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Knight committed Feb 27, 2020
1 parent 8215717 commit 262c224
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ VERBS.concat('any').forEach(function(method) {
timeout: function() {
return reply(function(config) {
var error = utils.createAxiosError(
'timeout of ' + config.timeout + 'ms exceeded',
config.timeoutErrorMessage || ('timeout of ' + config.timeout + 'ms exceeded'),
config,
undefined,
'ECONNABORTED'
Expand All @@ -149,7 +149,7 @@ VERBS.concat('any').forEach(function(method) {
timeoutOnce: function() {
return replyOnce(function(config) {
var error = utils.createAxiosError(
'timeout of ' + config.timeout + 'ms exceeded',
config.timeoutErrorMessage || ('timeout of ' + config.timeout + 'ms exceeded'),
config,
undefined,
'ECONNABORTED'
Expand Down
19 changes: 19 additions & 0 deletions test/timeout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,23 @@ describe('timeout spec', function() {
expect(response.status).to.equal(200);
});
});

it('responds with timeoutErrorMessage', function() {
mock.onGet('/foo').timeout();
var timeoutErrorMessage = 'That request sure did time out';

return instance.get('/foo', {
timeoutErrorMessage: timeoutErrorMessage
}).then(
function() {
expect.fail('should not be called');
},
function(error) {
expect(error.config).to.exist;
expect(error.code).to.equal('ECONNABORTED');
expect(error.message).to.equal(timeoutErrorMessage);
expect(error.isAxiosError).to.be.true;
}
);
});
});

0 comments on commit 262c224

Please # to comment.