Skip to content

Commit

Permalink
added some error handling (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
srossross authored Feb 3, 2025
1 parent 48074cd commit 71d34f8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/app/[ecosystem]/[...packageName]/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client"; // Error boundaries must be Client Components

import { useEffect } from "react";

export default function Error({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
}, [error]);

return (
<div>
<h2>Something went wrong!</h2>
<button
onClick={
// Attempt to recover by trying to re-render the segment
() => reset()
}
>
Try again
</button>
</div>
);
}
1 change: 1 addition & 0 deletions src/app/[ecosystem]/[...packageName]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Props = {
export default async function PackageScoreComponent({ params }: Props) {
const { ecosystem, packageName } = await params;
const name = packageName.join("/");

const [notes, { package: pkg, status, score, source }] = await Promise.all([
fetchNotes(),
fetchPackageScore(ecosystem, name),
Expand Down
Binary file removed src/app/favicon.ico
Binary file not shown.
Binary file added src/app/icon.ico
Binary file not shown.
4 changes: 4 additions & 0 deletions src/utils/score_res.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ export async function fetchPackageScore(
name: string,
): Promise<PackageScore> {
const url = `${BASE_URL}/score/${ecosystem.toLowerCase()}/${name}`;
console.debug(url);
const res = await fetch(url);
if (res.status != 200) {
throw new Error("Failed to fetch package score");
}
const data = await res.json();
return data;
}
Expand Down

0 comments on commit 71d34f8

Please sign in to comment.