File tree Expand file tree Collapse file tree 2 files changed +13
-8
lines changed
server/api/registry/org/[org] Expand file tree Collapse file tree 2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -92,11 +92,11 @@ export function useOrgPackages(orgName: MaybeRefOrGetter<string>) {
9292 // Get all package names in the org
9393 let packageNames : string [ ]
9494 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 ` ,
9797 { signal } ,
9898 )
99- packageNames = Object . keys ( data )
99+ packageNames = packages
100100 } catch ( err ) {
101101 // Check if this is a 404 (org not found)
102102 if ( err && typeof err === 'object' && 'statusCode' in err && err . statusCode === 404 ) {
Original file line number Diff line number Diff line change 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'
43
54// Validation pattern for npm org names (alphanumeric with hyphens)
65const NPM_ORG_NAME_RE = / ^ [ a - z 0 - 9 ] (?: [ a - z 0 - 9 - ] * [ a - z 0 - 9 ] ) ? $ / i
@@ -37,8 +36,14 @@ export default defineCachedEventHandler(
3736 packages : Object . keys ( data ) ,
3837 count : Object . keys ( data ) . length ,
3938 }
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 )
4247 return {
4348 packages : [ ] ,
4449 count : 0 ,
You can’t perform that action at this time.
0 commit comments