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

fix: navigating to org page from search leads to 404 page (#1191)

authored by philippeserhal.com and committed by

GitHub 6fb75c85 bf3df3e4

+13 -8
+3 -3
app/composables/npm/useOrgPackages.ts
··· 92 92 // Get all package names in the org 93 93 let packageNames: string[] 94 94 try { 95 - const { data } = await $npmRegistry<Record<string, string>>( 96 - `/-/org/${encodeURIComponent(org)}/package`, 95 + const { packages } = await $fetch<{ packages: string[]; count: number }>( 96 + `/api/registry/org/${encodeURIComponent(org)}/packages`, 97 97 { signal }, 98 98 ) 99 - packageNames = Object.keys(data) 99 + packageNames = packages 100 100 } catch (err) { 101 101 // Check if this is a 404 (org not found) 102 102 if (err && typeof err === 'object' && 'statusCode' in err && err.statusCode === 404) {
+10 -5
server/api/registry/org/[org]/packages.get.ts
··· 1 - import { CACHE_MAX_AGE_ONE_HOUR } from '#shared/utils/constants' 2 - 3 - const NPM_REGISTRY = 'https://registry.npmjs.org' 1 + import { CACHE_MAX_AGE_ONE_HOUR, NPM_REGISTRY } from '#shared/utils/constants' 2 + import { FetchError } from 'ofetch' 4 3 5 4 // Validation pattern for npm org names (alphanumeric with hyphens) 6 5 const NPM_ORG_NAME_RE = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i ··· 37 36 packages: Object.keys(data), 38 37 count: Object.keys(data).length, 39 38 } 40 - } catch { 41 - // Org doesn't exist or has no packages 39 + } catch (error) { 40 + // Let 404s propagate (org not found) so consumers can distinguish from empty 41 + if (error instanceof FetchError && error.statusCode === 404) { 42 + throw createError({ statusCode: 404, message: `Organization not found: ${org}` }) 43 + } 44 + // For other errors (network, etc.), return empty 45 + // oxlint-disable-next-line no-console -- log npm registry fetch errors for debugging 46 + console.warn(`[org-packages] Failed to fetch packages for org ${org}:`, error) 42 47 return { 43 48 packages: [], 44 49 count: 0,