Skip to content

Commit 155afff

Browse files
committed
エラーページもカスタマイズしてみた
1 parent 8f49aa2 commit 155afff

File tree

3 files changed

+54
-11
lines changed

3 files changed

+54
-11
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/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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import Link from "next/link";
22

33
export default function NotFound() {
44
return (
5-
<div className="p-4 flex-1 flex flex-col items-center justify-center">
5+
<div className="p-4 flex-1 w-max max-w-full mx-auto flex flex-col items-center justify-center">
66
<h1 className="text-2xl font-bold mb-4">404</h1>
77
<p>指定されたページが見つかりません。</p>
8-
<div className="divider w-80 max-w-full self-auto!" />
8+
<div className="divider w-full self-auto!" />
99
<Link href="/" className="btn btn-primary">
1010
トップに戻る
1111
</Link>

0 commit comments

Comments
 (0)