[READ-ONLY] a fast, modern browser for the npm registry
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: throw 404 statusCode instead of 400 (#418)

Co-authored-by: Daniel Roe <daniel@roe.dev>

authored by

Florian Heuberger
Daniel Roe
and committed by
GitHub
a4c82785 228de60c

+16 -8
+2 -1
server/api/registry/badge/[...pkg].get.ts
··· 14 14 async event => { 15 15 const pkgParamSegments = getRouterParam(event, 'pkg')?.split('/') ?? [] 16 16 if (pkgParamSegments.length === 0) { 17 - throw createError({ statusCode: 400, message: 'Package name is required.' }) 17 + // TODO: throwing 404 rather than 400 as it's cacheable 18 + throw createError({ statusCode: 404, message: 'Package name is required.' }) 18 19 } 19 20 20 21 const { rawPackageName, rawVersion } = parsePackageParams(pkgParamSegments)
+4 -2
server/api/registry/docs/[...pkg].get.ts
··· 8 8 async event => { 9 9 const pkgParam = getRouterParam(event, 'pkg') 10 10 if (!pkgParam) { 11 - throw createError({ statusCode: 400, message: 'Package name is required' }) 11 + // TODO: throwing 404 rather than 400 as it's cacheable 12 + throw createError({ statusCode: 404, message: 'Package name is required' }) 12 13 } 13 14 14 15 const { packageName, version: requestedVersion } = parsePackageParam(pkgParam) 15 16 16 17 if (!packageName) { 17 - throw createError({ statusCode: 400, message: 'Package name is required' }) 18 + // TODO: throwing 404 rather than 400 as it's cacheable 19 + throw createError({ statusCode: 404, message: 'Package name is required' }) 18 20 } 19 21 assertValidPackageName(packageName) 20 22
+2 -1
server/api/registry/file/[...pkg].get.ts
··· 106 106 107 107 if (versionSegments.length < 2) { 108 108 throw createError({ 109 - statusCode: 400, 109 + // TODO: throwing 404 rather than 400 as it's cacheable 110 + statusCode: 404, 110 111 message: ERROR_PACKAGE_VERSION_AND_FILE_FAILED, 111 112 }) 112 113 }
+4 -2
server/api/registry/org/[org]/packages.get.ts
··· 8 8 function validateOrgName(name: string): void { 9 9 if (!name || name.length > 50 || !NPM_ORG_NAME_RE.test(name)) { 10 10 throw createError({ 11 - statusCode: 400, 11 + // TODO: throwing 404 rather than 400 as it's cacheable 12 + statusCode: 404, 12 13 message: `Invalid org name: ${name}`, 13 14 }) 14 15 } ··· 20 21 21 22 if (!org) { 22 23 throw createError({ 23 - statusCode: 400, 24 + // TODO: throwing 404 rather than 400 as it's cacheable 25 + statusCode: 404, 24 26 message: 'Org name is required', 25 27 }) 26 28 }
+2 -1
server/utils/error-handler.ts
··· 16 16 // Handle Valibot validation errors 17 17 if (v.isValiError(error)) { 18 18 throw createError({ 19 - statusCode: 400, 19 + // TODO: throwing 404 rather than 400 as it's cacheable 20 + statusCode: 404, 20 21 message: error.issues[0].message, 21 22 }) 22 23 }
+2 -1
shared/utils/npm.ts
··· 10 10 if (!result.validForNewPackages && !result.validForOldPackages) { 11 11 const errors = [...(result.errors ?? []), ...(result.warnings ?? [])] 12 12 throw createError({ 13 - statusCode: 400, 13 + // TODO: throwing 404 rather than 400 as it's cacheable 14 + statusCode: 404, 14 15 message: `Invalid package name: ${errors[0] ?? 'unknown error'}`, 15 16 }) 16 17 }