Skip to content

Commit

Permalink
updated error message when ecosystem is incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
karamba228 committed Feb 6, 2025
1 parent 6b40728 commit e167bcf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/app/[ecosystem]/[...packageName]/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ export default function Error({
console.error(error);
}, [error]);

const invalidEcosystemMatch = error.message.match(/(.+?) doesn't exist/);
const invalidEcosystem = invalidEcosystemMatch ? invalidEcosystemMatch[1] : null;

return (
<div>
<h2>Something went wrong!</h2>
{invalidEcosystem ? (
<p>{invalidEcosystem} doesn't exist</p>
) : (
<p>An unexpected error occurred.</p>
)}
<button
onClick={
// Attempt to recover by trying to re-render the segment
Expand Down
6 changes: 6 additions & 0 deletions src/app/[ecosystem]/[...packageName]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ type Props = {
}>;
};

const VALID_ECOSYSTEMS = ["pypi", "conda", "npm"];

export default async function PackageScoreComponent({ params }: Props) {
const { ecosystem, packageName } = await params;
const name = packageName.join("/");

if (!VALID_ECOSYSTEMS.includes(ecosystem)) {
throw new Error(`${ecosystem} doesn't exist`);
}

const [notes, { package: pkg, status, score, source }] = await Promise.all([
fetchNotes(),
fetchPackageScore(ecosystem, name),
Expand Down

0 comments on commit e167bcf

Please sign in to comment.