From 262c224d7e108ad5154f82a061d6c819ee22a812 Mon Sep 17 00:00:00 2001 From: Cameron Knight Date: Thu, 27 Feb 2020 13:05:14 -0800 Subject: [PATCH] Handle timeoutErrorMessage if provided --- src/index.js | 4 ++-- test/timeout.spec.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 25b8bc7..ebf6843 100644 --- a/src/index.js +++ b/src/index.js @@ -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' @@ -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' diff --git a/test/timeout.spec.js b/test/timeout.spec.js index 6bda8cc..bdaa24c 100644 --- a/test/timeout.spec.js +++ b/test/timeout.spec.js @@ -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; + } + ); + }); });