Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Feb 3, 2025
1 parent 9db0595 commit a0b5da4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/app/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { config } from "@common/config";
import { ConfigProvider } from "@components/utils/ConfigProvider";
import { FeatureStatusProvider } from "@components/utils/FeatureStatusProvider";
import { Matomo } from "@components/utils/Matomo";
import { SentryErrorBoundary } from "@components/utils/SentryErrorBoundary";
import { ClientAnimate } from "@design-system/utils/client/ClientAnimate";
import { SkeletonTheme } from "@design-system/utils/client/skeleton";
import { headers } from "next/headers";
Expand Down Expand Up @@ -101,7 +102,9 @@ const RootLayout = ({ children }: PropsWithChildren) => {
]}
/>
<ConsentBannerAndConsentManagement />
<ConfigProvider config={mcpconfig}>{children}</ConfigProvider>
<ConfigProvider config={mcpconfig}>
<SentryErrorBoundary>{children}</SentryErrorBoundary>
</ConfigProvider>
</SkeletonTheme>
</DsfrProvider>
</SessionProvider>
Expand Down
43 changes: 43 additions & 0 deletions packages/app/src/components/utils/SentryErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use client";

import * as Sentry from "@sentry/nextjs";
import { Component, type PropsWithChildren } from "react";

interface State {
hasError: boolean;
}

export class SentryErrorBoundary extends Component<PropsWithChildren, State> {
constructor(props: PropsWithChildren) {
super(props);
this.state = { hasError: false };
}

public static getDerivedStateFromError(): State {
return { hasError: true };
}

public componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void {
console.log("Error caught by Sentry boundary:", error, errorInfo);
Sentry.captureException(error, {
contexts: {
react: {
componentStack: errorInfo.componentStack,
},
},
});
}

public render(): React.ReactNode {
if (this.state.hasError) {
return (
<div className="fr-alert fr-alert--error fr-my-3w">
<h3 className="fr-alert__title">Une erreur est survenue</h3>
<p>L'erreur a été signalée automatiquement à notre équipe.</p>
</div>
);
}

return this.props.children;
}
}

0 comments on commit a0b5da4

Please sign in to comment.