Skip to content

Commit

Permalink
Merge pull request #1075 from annuaire-entreprises-data-gouv-fr/TMP-f…
Browse files Browse the repository at this point in the history
…ix-error

chore: log separately error that result in a 500 error page displayed
  • Loading branch information
johangirod authored May 28, 2024
2 parents 707a60f + f4d8993 commit 55416f8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/global-error.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use client';

import NextError from 'next/error';
import { useLogFatalErrorAppClient } from 'hooks';
import { useLog500ErrorAppClient } from 'hooks';

export default function GlobalError({
error,
}: {
error: Error & { digest?: string };
}) {
useLogFatalErrorAppClient(error);
useLog500ErrorAppClient(error);
return (
<html>
<body>
Expand Down
2 changes: 1 addition & 1 deletion hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './fetch/index';

export { useHeightTransition } from './use-height-transition';
export { useLogFatalErrorAppClient } from './use-log-fatal-error-app-client';
export * from './use-log-fatal-error-app-client';
export { useMeasure } from './use-measure';
export { useOutsideClick } from './use-outside-click';
export { usePrefersReducedMotion } from './use-prefers-reduced-motion';
Expand Down
17 changes: 17 additions & 0 deletions hooks/use-log-fatal-error-app-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect } from 'react';
import { Exception } from '#models/exceptions';
import { logFatalErrorInSentry } from '#utils/sentry';
export type NextAppError = Error & { digest?: string };

export function useLogFatalErrorAppClient(error: Error & { digest?: string }) {
useEffect(() => {
// Log the error to Sentry
Expand All @@ -17,3 +18,19 @@ export function useLogFatalErrorAppClient(error: Error & { digest?: string }) {
);
}, [error]);
}

export function useLog500ErrorAppClient(error: Error & { digest?: string }) {
useEffect(() => {
// Log the error to Sentry
logFatalErrorInSentry(
new Exception({
name: 'Client500PageDisplayed',
cause: error,
context: {
digest: error.digest,
page: window.location.pathname,
},
})
);
}, [error]);
}

0 comments on commit 55416f8

Please sign in to comment.