From ba85fa767820fad69a6007846964d706e942a1db Mon Sep 17 00:00:00 2001 From: VictorAugDB Date: Tue, 24 May 2022 11:40:49 -0300 Subject: [PATCH 1/2] 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 --- lib/adapters/http.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 8d3588b1f9..fc872514c5 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 From be442af821826faa2b2b52a464acadda43f069d4 Mon Sep 17 00:00:00 2001 From: VictorAugDB Date: Tue, 24 May 2022 11:40:59 -0300 Subject: [PATCH 2/2] 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 --- test/unit/adapters/http.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/adapters/http.js b/test/unit/adapters/http.js index 8804bd2d0b..ed3db64b5f 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); });