Skip to content

Commit

Permalink
Fix invalid package name should show not found (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
btea authored Aug 20, 2023
1 parent 313d6d2 commit f5e8c9a
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions site/src/pages/Package.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,18 @@
// prettier-ignore
`${import.meta.env.VITE_NPM_REGISTRY}/${encodeURIComponent(npmPkgName)}/latest`
)
.then((v) => v.ok && v.json())
.then((v) => {
if (v?.version) {
url.replace(`/${npmPkgName}@${v.version}`)
}
})
.finally(() => {
versionFetched = true
})
.then(async (res) => {
const result = await res.json()
if (typeof result === 'string') {
error = result
return
}
if (result?.version) {
url.replace(`/${npmPkgName}@${result.version}`)
}
}).finally(() => {
versionFetched = true
})
}
/** @type {Worker} */
Expand Down Expand Up @@ -146,7 +149,9 @@
{#if npmPkgName}
<h1 class="mt-10 mb-0 font-600">
{npmPkgName}
<PackageVersion version={npmPkgVersion} pkgName={npmPkgName} />
{#if !error}
<PackageVersion version={npmPkgVersion} pkgName={npmPkgName} />
{/if}
</h1>
<p class="flex flex-row justify-center items-center gap-4 mb-10">
{#if repo}
Expand Down

0 comments on commit f5e8c9a

Please sign in to comment.