Skip to content

Commit 0121e21

Browse files
committed
Added a component to capture global errors issued by NextJS for Sentry
1 parent 8c3b8aa commit 0121e21

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

app/global-error.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// Route des erreurs globales émises par Next.js.
3+
// Source : https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#react-render-errors-in-app-router
4+
//
5+
6+
"use client";
7+
8+
// Importation des dépendances.
9+
import NextError from "next/error";
10+
import { useEffect } from "react";
11+
import { captureException } from "@sentry/nextjs";
12+
13+
export default function GlobalError( {
14+
error
15+
}: {
16+
error: Error & { digest?: string };
17+
} )
18+
{
19+
// Capture de l'erreur avec Sentry.
20+
useEffect( () =>
21+
{
22+
captureException( error );
23+
}, [ error ] );
24+
25+
// Affichage du rendu HTML du composant.
26+
return (
27+
<html lang="en">
28+
<body>
29+
<NextError statusCode={undefined as never} />
30+
</body>
31+
</html>
32+
);
33+
}

0 commit comments

Comments
 (0)