From 8af91528ce6277cd3a8c7ca8c8102671baf10d2f Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Tue, 3 Oct 2017 21:56:54 -0700 Subject: error-message: Add custom error messages --- lib/utils/error-message.js | 48 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/utils/error-message.js b/lib/utils/error-message.js index 49aa9124e..028a18bbb 100644 --- a/lib/utils/error-message.js +++ b/lib/utils/error-message.js @@ -66,8 +66,52 @@ function errorMessage (er) { ]) break - // TODO(isaacs) - // Add a special case here for E401 and E403 explaining auth issues? + case 'EOTP': + short.push(['', 'This operation requires a one-time password from your authenticator.']) + detail.push([ + '', + [ + 'You can provide a one-time password by passing --otp= to the command you ran.', + 'If you already provided a one-time password then it is likely that you either typoed', + 'it, or it timed out. Please try again.' + ].join('\n') + ]) + break + + case 'E401': + // npm ERR! code E401 + // npm ERR! Unable to authenticate, need: Basic + if (er.headers && er.headers['www-authenticate']) { + const auth = er.headers['www-authenticate'] + if (auth.indexOf('Bearer') !== -1) { + short.push(['', 'Unable to authenticate, your authentication token seems to be invalid.']) + detail.push([ + '', + [ + 'To correct this please trying logging in again with:', + ' npm login' + ].join('\n') + ]) + break + } else if (auth.indexOf('Basic') !== -1) { + short.push(['', 'Incorrect or missing password.']) + detail.push([ + '', + [ + 'If you were trying to login, change your password, create an', + 'authentication token or enable two-factor authentication then', + 'that means you likely typed your password in incorectly.', + 'Please try again, or recover your password at:', + ' https://www.npmjs.com/forgot', + '', + 'If you were doing some other operation then your saved credentials are', + 'probably out of date. To correct this please try logging in again with:', + ' npm login' + ].join('\n') + ]) + break + } + } case 'E404': // There's no need to have 404 in the message as well. -- cgit v1.2.3