Skip to content

Commit 6e47325

Browse files
authored
fix: Makes 404 errors less scary without revealing existence (#8441)
closes #8257
1 parent 6dbe21a commit 6e47325

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/utils/error-message.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ const errorMessage = (er, npm) => {
165165
const pkg = er.pkgid.replace(/(?!^)@.*$/, '')
166166

167167
detail.push(['404', ''])
168-
detail.push(['404', '', `'${replaceInfo(er.pkgid)}' is not in this registry.`])
168+
detail.push([
169+
'404',
170+
'',
171+
`The requested resource '${replaceInfo(er.pkgid)}' could not be found or you do not have permission to access it.`,
172+
])
169173

170174
const nameValidator = require('validate-npm-package-name')
171175
const valResult = nameValidator(pkg)

tap-snapshots/test/lib/utils/error-message.js.test.cjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Object {
1515
Array [
1616
"404",
1717
"",
18-
"'http://evil:***@npmjs.org/not-found' is not in this registry.",
18+
"The requested resource 'http://evil:***@npmjs.org/not-found' could not be found or you do not have permission to access it.",
1919
],
2020
Array [
2121
"404",
@@ -58,7 +58,7 @@ Object {
5858
Array [
5959
"404",
6060
"",
61-
"'node_modules' is not in this registry.",
61+
"The requested resource 'node_modules' could not be found or you do not have permission to access it.",
6262
],
6363
Array [
6464
"404",
@@ -101,7 +101,7 @@ Object {
101101
Array [
102102
"404",
103103
"",
104-
"'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' is not in this registry.",
104+
"The requested resource 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' could not be found or you do not have permission to access it.",
105105
],
106106
Array [
107107
"404",
@@ -156,7 +156,7 @@ Object {
156156
Array [
157157
"404",
158158
"",
159-
"'yolo' is not in this registry.",
159+
"The requested resource 'yolo' could not be found or you do not have permission to access it.",
160160
],
161161
Array [
162162
"404",

0 commit comments

Comments
 (0)