From f61141570b3861dc89d19263450a967caf60a072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Wed, 19 Dec 2018 09:31:38 -0800 Subject: [PATCH] audit: report any errors above 400 as potentially not supporting audit Fixes: https://npm.community/t/npm-audit-fails-with-enoaudit-on-500-response/3629 Fixes: https://npm.community/t/npm-audit-error-messaging-update-for-401s/3983 --- lib/audit.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/audit.js b/lib/audit.js index 076ca256b7c72..2cabef9d27d0d 100644 --- a/lib/audit.js +++ b/lib/audit.js @@ -189,8 +189,16 @@ function auditCmd (args, cb) { }).then((auditReport) => { return audit.submitForFullReport(auditReport) }).catch((err) => { - if (err.statusCode === 404 || err.statusCode >= 500) { - const ne = new Error(`Your configured registry (${opts.registry}) does not support audit requests.`) + if (err.statusCode >= 400) { + let msg + if (err.statusCode === 401) { + msg = `Either your login credentials are invalid or your registry (${opts.registry}) does not support audit.` + } else if (err.statusCode === 404) { + msg = `Your configured registry (${opts.registry}) does not support audit requests.` + } else { + msg = `Your configured registry (${opts.registry}) does not support audit requests, or the audit endpoint is temporarily unavailable.` + } + const ne = new Error(msg) ne.code = 'ENOAUDIT' ne.wrapped = err throw ne