Skip to content

Commit

Permalink
GlobalErrorコンポーネントにエラーログ出力機能を追加し、リセットボタンを実装しました。エラーオブジェクトの詳細情報をコンソールに…
Browse files Browse the repository at this point in the history
…出力するようにしました。 (#622)
  • Loading branch information
ttizze authored Feb 26, 2025
2 parents 511c20c + 2b8a9bf commit e568503
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion next/src/app/global-error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,25 @@ import { useEffect } from "react";

export default function GlobalError({
error,
}: { error: Error & { digest?: string } }) {
reset,
}: { error: Error & { digest?: string }; reset: () => void }) {
useEffect(() => {
// エラーオブジェクトの詳細情報をコンソールに出力
console.error("Error object:", error);

// エラーオブジェクトのプロパティを列挙
console.error("Error properties:", Object.getOwnPropertyNames(error));

// Response オブジェクトの場合の追加情報
if (error.toString() === "[object Response]") {
const responseError = error as unknown as Response;
console.error("Response details:", {
status: responseError.status,
url: responseError.url,
type: responseError.type,
redirected: responseError.redirected,
});
}
Sentry.captureException(error);
}, [error]);

Expand All @@ -19,6 +36,9 @@ export default function GlobalError({
does not expose status codes for errors, we simply pass 0 to render a
generic error message. */}
<NextError statusCode={0} />
<button onClick={() => reset()} type="button">
Reset error boundary
</button>
</body>
</html>
);
Expand Down

0 comments on commit e568503

Please sign in to comment.