Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions package/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ it.concurrent('latest', async () => {
specifier: '=7.0.3',
version: '7.0.3',
})

expect(
await getLatestVersion('axios@150.150.150', { apiEndpoint, throw: false }),
).toMatchObject({
name: 'axios@150.150.150',
error: 'Version 150.150.150 of package axios not found',
})

await expect(
getLatestVersion('axios@150.150.150', { apiEndpoint }),
).rejects.toThrow('Version 150.150.150 of package axios not found')
})

it.concurrent('versions', async () => {
Expand Down Expand Up @@ -361,13 +372,13 @@ describe.concurrent('complex package names, complex versions', async () => {
})

it('multi-word package name with pre release version with hyphen in specifier', async () => {
const result = await fetchApi(`${apiEndpoint}/${pkgName}@1.0.0-pr.6`).then(
const result = await fetchApi(`${apiEndpoint}/${pkgName}@1.0.0-rc.4`).then(
r => r.json(),
)
expect(result).toMatchObject({
name: pkgName,
specifier: '1.0.0-pr.6',
version: '1.0.0-pr.6',
specifier: '1.0.0-rc.4',
version: '1.0.0-rc.4',
lastSynced: expect.any(Number),
})
})
Expand Down
6 changes: 6 additions & 0 deletions server/routes/[...pkg].ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export default eventHandler(async (event) => {
else if (spec.type === 'version') {
version = semver.clean(spec.fetchSpec, true)
specifier = spec.fetchSpec
if (version && !data.versionsMeta[version]) {
throw createError({
status: 404,
message: `Version ${version} of package ${spec.name} not found`,
})
}
}
else {
throw new Error(`Unsupported spec: ${JSON.stringify(spec)}`)
Expand Down
2 changes: 1 addition & 1 deletion server/utils/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function handlePackagesQuery<T extends object>(
})
.catch((error) => {
results[idx] = {
status: error.status ?? DEFAULT_ERROR_STATUS,
status: error.statusCode ?? error.status ?? DEFAULT_ERROR_STATUS,
name: parsedSpec.raw,
error: retrieveErrorMessage(error),
}
Expand Down