diff --git a/README.md b/README.md index 2c90941..4d3ff32 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ pnpm dev ## Learn More ```bash +pnpm test pnpm lint pnpm build ``` diff --git a/components/shortener.tsx b/components/shortener.tsx index 8b270d5..e605cf8 100644 --- a/components/shortener.tsx +++ b/components/shortener.tsx @@ -7,7 +7,7 @@ import { Check, Copy, Link2, Loader2, TriangleAlert } from "lucide-react" import { useState } from "react" type Result = - | { status: "ok"; owner: string; repo: string; path: string; fullName: string } + | { status: "ok"; owner: string; repo: string; path: string; fullName: string; limited?: true } | { status: "miss"; reason: string } | { status: "idle" } @@ -25,7 +25,9 @@ export function Shortener() { setResult(null) try { const res = await fetch(`/api/shorten?repo=${encodeURIComponent(repo)}`) - setResult((await res.json()) as Result) + const data = (await res.json().catch(() => null)) as Result | null + if (!res.ok || !data) throw new Error("Invalid shortener response") + setResult(data) } catch { setResult({ status: "miss", reason: "Lookup failed" }) } finally { @@ -69,7 +71,9 @@ export function Shortener() { {SITE_HOST}/{result.path} - resolves to {result.fullName} + + {result.limited ? "Search quota limited; using the exact path" : `resolves to ${result.fullName}`} +