Skip to content

Commit d856767

Browse files
committed
fix: handle non-existent org
1 parent baf53b4 commit d856767

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

app/composables/useNpmRegistry.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,18 @@ export function useNpmSearch(
250250
/**
251251
* Fetch all package names in an npm organization
252252
* Uses the /-/org/{org}/package endpoint
253+
* Returns empty array if org doesn't exist or has no packages
253254
*/
254255
async function fetchOrgPackageNames(orgName: string): Promise<string[]> {
255-
const data = await $fetch<Record<string, string>>(
256-
`${NPM_REGISTRY}/-/org/${encodeURIComponent(orgName)}/package`,
257-
)
258-
return Object.keys(data)
256+
try {
257+
const data = await $fetch<Record<string, string>>(
258+
`${NPM_REGISTRY}/-/org/${encodeURIComponent(orgName)}/package`,
259+
)
260+
return Object.keys(data)
261+
} catch {
262+
// Org doesn't exist or has no packages
263+
return []
264+
}
259265
}
260266

261267
/**

0 commit comments

Comments
 (0)