From 4755b072877f547585cb0e2562261b2c87e2ff0b Mon Sep 17 00:00:00 2001 From: nlf Date: Thu, 1 Jul 2021 15:08:52 -0700 Subject: [PATCH] fix: friendlier errors for ERR_SOCKET_TIMEOUT PR-URL: https://github.com/npm/cli/pull/3498 Credit: @nlf Close: #3498 Reviewed-by: @wraithgar --- lib/utils/error-message.js | 1 + .../test/lib/utils/error-message.js.test.cjs | 23 +++++++++++++++++++ test/lib/utils/error-message.js | 1 + 3 files changed, 25 insertions(+) diff --git a/lib/utils/error-message.js b/lib/utils/error-message.js index 125cdf8c53581..3b590f712e783 100644 --- a/lib/utils/error-message.js +++ b/lib/utils/error-message.js @@ -269,6 +269,7 @@ module.exports = (er, npm) => { case 'ECONNRESET': case 'ENOTFOUND': case 'ETIMEDOUT': + case 'ERR_SOCKET_TIMEOUT': case 'EAI_FAIL': short.push(['network', er.message]) detail.push([ diff --git a/tap-snapshots/test/lib/utils/error-message.js.test.cjs b/tap-snapshots/test/lib/utils/error-message.js.test.cjs index 7b02dbd9aaa65..5b6e3c85ab112 100644 --- a/tap-snapshots/test/lib/utils/error-message.js.test.cjs +++ b/tap-snapshots/test/lib/utils/error-message.js.test.cjs @@ -1289,6 +1289,29 @@ Object { } ` +exports[`test/lib/utils/error-message.js TAP just simple messages > must match snapshot 23`] = ` +Object { + "detail": Array [ + Array [ + "network", + String( + This is a problem related to network connectivity. + In most cases you are behind a proxy or have bad network settings. + + If you are behind a proxy, please make sure that the + 'proxy' config is set properly. See: 'npm help config' + ), + ], + ], + "summary": Array [ + Array [ + "network", + "foo", + ], + ], +} +` + exports[`test/lib/utils/error-message.js TAP just simple messages > must match snapshot 3`] = ` Object { "detail": Array [ diff --git a/test/lib/utils/error-message.js b/test/lib/utils/error-message.js index 4f94645a4542d..3fdfb8cc25089 100644 --- a/test/lib/utils/error-message.js +++ b/test/lib/utils/error-message.js @@ -97,6 +97,7 @@ t.test('just simple messages', t => { 'ETOOMANYARGS', 'ETARGET', 'E403', + 'ERR_SOCKET_TIMEOUT', ] t.plan(codes.length) codes.forEach(code => {