Skip to content

Commit 93ec162

Browse files
committed
fix: show error only in compare-form, remove duplicate from result-dashboard
- Remove duplicate error Alert block from page.tsx (was shown twice) - Error is now displayed only via CompareForm's error prop - Improve invalid username detection in API route to handle GraphqlResponseError format from @octokit/graphql (catches 'Could not resolve to a User' messages) Signed-off-by: Ai-chan-0411 (藍) <aoikabu12@gmail.com>
1 parent 193c50e commit 93ec162

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

app/api/compare/route.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,30 @@ export async function GET(request: Request) {
4040
let message = "Something went wrong. Please try again later.";
4141
let status = 500;
4242

43-
const msg = error?.message ?? "";
44-
if (msg === "User not found") {
43+
const msg = (error?.message ?? "").toLowerCase();
44+
const isNotFound =
45+
msg === "user not found" ||
46+
msg.includes("could not resolve to a user") ||
47+
msg.includes("user not found") ||
48+
error?.errors?.some((e: any) =>
49+
e?.type === "NOT_FOUND" || e?.message?.toLowerCase().includes("user")
50+
);
51+
52+
if (isNotFound) {
4553
message =
4654
"One or more GitHub users could not be found. Please check the usernames and try again.";
4755
status = 404;
4856
} else if (
4957
msg.includes("rate limit") ||
50-
msg.includes("API rate limit") ||
58+
msg.includes("api rate limit") ||
5159
error?.status === 403
5260
) {
5361
message =
5462
"GitHub API rate limit exceeded. Please wait a few minutes and try again.";
5563
status = 429;
5664
} else if (
57-
msg.includes("ENOTFOUND") ||
58-
msg.includes("ECONNREFUSED") ||
65+
msg.includes("enotfound") ||
66+
msg.includes("econnrefused") ||
5967
msg.includes("fetch failed")
6068
) {
6169
message =

app/page.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { CompareForm } from "../components/compare-form";
55
import { ResultDashboard } from "../components/result-dashboard";
66
import { DashboardSkeleton } from "../components/skeletons";
77
import { UserResult } from "@/types/user-result";
8-
import { AlertCircle } from "lucide-react";
9-
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
108

119
type ApiResponse = {
1210
success: boolean;
@@ -76,7 +74,7 @@ export default function HomePage() {
7674
DevImpact
7775
</span>
7876
</div>
79-
77+
8078
</div>
8179
</header>
8280
<div className="max-w-6xl mx-auto px-4 py-10 space-y-6">
@@ -90,13 +88,6 @@ export default function HomePage() {
9088
/>
9189

9290
{loading && skeleton}
93-
{error && (
94-
<Alert variant="destructive">
95-
<AlertCircle className="h-4 w-4" />
96-
<AlertTitle>Comparison Failed</AlertTitle>
97-
<AlertDescription>{error}</AlertDescription>
98-
</Alert>
99-
)}
10091
{data && <ResultDashboard user1={data.user1} user2={data.user2} />}
10192
{!loading && !error && !data && (
10293
<div className="flex flex-col items-center justify-center py-20 text-center text-muted-foreground gap-4">

0 commit comments

Comments
 (0)