From a11f9501b823a167de7187ee542e4204ad1a517a Mon Sep 17 00:00:00 2001 From: Victor Augusto Date: Sat, 28 May 2022 06:46:33 -0300 Subject: [PATCH] Fix/4737/timeout error message for http (#4738) * Fixing timeoutErrorMessage in http calls When timeoutErrorMessage was set this did not change anything in the error message, with this change the error message will be the configured message * Testing timeoutErrorMessage in http calls When timeoutErrorMessage was set this did not change anything in the error message, with this change the error message will be the configured message Co-authored-by: Jay --- lib/adapters/http.js | 6 +++++- test/unit/adapters/http.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 8d3588b..fc87251 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -420,9 +420,13 @@ module.exports = function httpAdapter(config) { // ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect. req.setTimeout(timeout, function handleRequestTimeout() { req.abort(); + var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded'; var transitional = config.transitional || transitionalDefaults; + if (config.timeoutErrorMessage) { + timeoutErrorMessage = config.timeoutErrorMessage; + } reject(new AxiosError( - 'timeout of ' + timeout + 'ms exceeded', + timeoutErrorMessage, transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED, config, req diff --git a/test/unit/adapters/http.js b/test/unit/adapters/http.js index 8804bd2..ed3db64 100644 --- a/test/unit/adapters/http.js +++ b/test/unit/adapters/http.js @@ -146,7 +146,7 @@ describe('supports http with nodejs', function () { assert.strictEqual(success, false, 'request should not succeed'); assert.strictEqual(failure, true, 'request should fail'); assert.strictEqual(error.code, 'ECONNABORTED'); - assert.strictEqual(error.message, 'timeout of 250ms exceeded'); + assert.strictEqual(error.message, 'oops, timeout'); done(); }, 300); });