Skip to content

Commit 3a2b6fa

Browse files
committed
404とエラーページのカスタマイズ
1 parent 56dfaac commit 3a2b6fa

File tree

4 files changed

+67
-10
lines changed

4 files changed

+67
-10
lines changed

app/error.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"use client"; // Error boundaries must be Client Components
2+
3+
import clsx from "clsx";
4+
import Link from "next/link";
5+
6+
export default function Error({
7+
error,
8+
reset,
9+
}: {
10+
error: Error & { digest?: string };
11+
reset: () => void;
12+
}) {
13+
return (
14+
<div className="p-4 flex-1 w-max max-w-full mx-auto flex flex-col items-center justify-center">
15+
<h1 className="text-2xl font-bold mb-4">エラー</h1>
16+
<p>ページの読み込み中にエラーが発生しました。</p>
17+
<pre
18+
className={clsx(
19+
"border-2 border-current/20 mt-4 rounded-box p-4! bg-base-300! text-base-content!",
20+
"max-w-full whitespace-pre-wrap"
21+
)}
22+
>
23+
{error.message}
24+
</pre>
25+
{error.digest && (
26+
<p className="mt-2 text-sm text-base-content/50">
27+
Digest: {error.digest}
28+
</p>
29+
)}
30+
<div className="divider w-full self-auto!" />
31+
<div className="flex flex-row gap-4">
32+
<button
33+
className="btn btn-warning"
34+
onClick={
35+
// Attempt to recover by trying to re-render the segment
36+
() => reset()
37+
}
38+
>
39+
やりなおす
40+
</button>
41+
<Link href="/" className="btn btn-primary">
42+
トップに戻る
43+
</Link>
44+
</div>
45+
</div>
46+
);
47+
}

app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function RootLayout({
2727
{/* mocha.css がbodyに背景色などを設定してしまうので、それを上書きしている */}
2828
<AutoAnonymousLogin />
2929
<SidebarMdProvider>
30-
<div className="drawer lg:drawer-open">
30+
<div className="drawer lg:drawer-open min-h-screen">
3131
<input
3232
id="drawer-toggle"
3333
type="checkbox"

app/lib/chatHistory.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,11 @@ async function initAll(ctx?: Partial<Context>): Promise<Context> {
3737
ctx.auth = await getAuthServer(ctx.drizzle);
3838
}
3939
if (!ctx.userId) {
40-
try {
41-
const session = await ctx.auth.api.getSession({
42-
headers: await headers(),
43-
});
44-
if (session) {
45-
ctx.userId = session.user.id;
46-
}
47-
} catch (e) {
48-
console.error("Failed to get session in initAll:", e);
40+
const session = await ctx.auth.api.getSession({
41+
headers: await headers(),
42+
});
43+
if (session) {
44+
ctx.userId = session.user.id;
4945
}
5046
}
5147
return ctx as Context;

app/not-found.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Link from "next/link";
2+
3+
export default function NotFound() {
4+
return (
5+
<div className="p-4 flex-1 w-max max-w-full mx-auto flex flex-col items-center justify-center">
6+
<h1 className="text-2xl font-bold mb-4">404</h1>
7+
<p>指定されたページが見つかりません。</p>
8+
<div className="divider w-full self-auto!" />
9+
<Link href="/" className="btn btn-primary">
10+
トップに戻る
11+
</Link>
12+
</div>
13+
);
14+
}

0 commit comments

Comments
 (0)