Skip to content

Commit 86439b4

Browse files
committed
fix: check endpoint response status before parsing
1 parent 8245d7e commit 86439b4

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

server/api/registry/badge/[type]/[...pkg].get.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ async function fetchInstallSize(packageName: string, version: string): Promise<n
258258

259259
async function fetchEndpointBadge(url: string) {
260260
const response = await fetch(url, { headers: { Accept: 'application/json' } })
261+
if (!response.ok) {
262+
throw createError({ statusCode: 502, message: `Endpoint returned ${response.status}` })
263+
}
261264
const data = await response.json()
262265
const parsed = v.parse(EndpointResponseSchema, data)
263266
return {

0 commit comments

Comments
 (0)