From aea7540590f27522ba004347f6c25ec7d67a1e16 Mon Sep 17 00:00:00 2001 From: Vensin Date: Thu, 12 Nov 2026 11:09:07 +0100 Subject: [PATCH] feat: 404 and error pages as inkan answers them A problem+json card with the address asked for, the stamp, search and the ways back. error.tsx keeps the nav and offers a retry; global-error.tsx stands on its own. --- app/error.tsx | 38 ++++++++++++ app/global-error.tsx | 32 ++++++++++ app/not-found.tsx | 20 ++++++ components/problem-page.tsx | 120 ++++++++++++++++++++++++++++++++++++ 4 files changed, 210 insertions(+) create mode 100644 app/error.tsx create mode 100644 app/global-error.tsx create mode 100644 app/not-found.tsx create mode 100644 components/problem-page.tsx diff --git a/app/error.tsx b/app/error.tsx new file mode 100644 index 0000000..b98868c --- /dev/null +++ b/app/error.tsx @@ -0,0 +1,38 @@ +"use client"; +import { useEffect } from "react"; +import { Footer, Nav } from "@/components/landing/chrome"; +import { ProblemPage } from "@/components/problem-page"; + +export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) { + useEffect(() => console.error(error), [error]); + return ( +
+
+ ); +} diff --git a/app/global-error.tsx b/app/global-error.tsx new file mode 100644 index 0000000..7c3b94d --- /dev/null +++ b/app/global-error.tsx @@ -0,0 +1,32 @@ +"use client"; +// When the root layout itself fails: no providers, so no nav and no search. +import "./globals.css"; +import { ProblemPage } from "@/components/problem-page"; + +export default function GlobalError({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) { + return ( + + + + Try again + + } + > +

Something below every page failed. Trying again usually helps.

+
+ + + ); +} diff --git a/app/not-found.tsx b/app/not-found.tsx new file mode 100644 index 0000000..c98c2b2 --- /dev/null +++ b/app/not-found.tsx @@ -0,0 +1,20 @@ +import type { Metadata } from "next"; +import { Footer, Nav } from "@/components/landing/chrome"; +import { ProblemPage } from "@/components/problem-page"; + +export const metadata: Metadata = { title: "Not found", robots: { index: false } }; + +export default function NotFound() { + return ( +
+
+ ); +} diff --git a/components/problem-page.tsx b/components/problem-page.tsx new file mode 100644 index 0000000..36c5082 --- /dev/null +++ b/components/problem-page.tsx @@ -0,0 +1,120 @@ +"use client"; +// 404 and 500 as inkan answers them: an RFC 9457 problem, with the way back next to it. +import { motion } from "motion/react"; +import Link from "next/link"; +import { usePathname } from "next/navigation"; +import { useSearchContext } from "fumadocs-ui/contexts/search"; +import type { ReactNode } from "react"; +import { Seal } from "@/components/seal"; + +const WAYS = [ + { href: "/docs", label: "Docs", note: "start at the contract" }, + { href: "/hanko", label: "Hanko", note: "plugins, middleware, stores" }, + { href: "/blog", label: "Blog", note: "what changed lately" }, + { href: "/", label: "Home", note: "the front page" }, +]; + +function SearchButton() { + const { setOpenSearch } = useSearchContext(); + return ( + + ); +} + +function Response({ status, reason, problem }: { status: number; reason: string; problem: Record }) { + const entries = Object.entries(problem); + return ( +
+
+ + + + response +
+
+        HTTP/1.1 
+        
+          {status} {reason}
+        
+        {"\n"}
+        content-type: application/problem+json{"\n\n"}
+        {"{\n"}
+        {entries.map(([k, v], i) => (
+          
+            {"  "}
+            "{k}":{" "}
+            {typeof v === "number" ? {v} : "{v}"}
+            {i < entries.length - 1 ? "," : ""}
+            {"\n"}
+          
+        ))}
+        {"}"}
+      
+
+ ); +} + +export function ProblemPage({ + status, + reason, + headline, + children, + detail, + extra, + actions, + search = true, +}: { + status: number; + reason: string; + headline: string; + children: ReactNode; + /** `{path}` becomes the address asked for */ + detail: string; + extra?: Record; + actions?: ReactNode; + search?: boolean; +}) { + const path = usePathname() ?? "/"; + return ( +
+
+ + + +

印 {status}

+

{headline}

+
{children}
+
+ {actions} + {search && } +
+
    + {WAYS.map((w) => ( +
  • + + {w.label} → + {w.note} + +
  • + ))} +
+
+ + +

An inkan app answers every error like this: application/problem+json, RFC 9457.

+
+
+ ); +}