-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add unified ErrorHandler component #1697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import Bugsnag from "@bugsnag/js"; | ||
| import { useEffect } from "react"; | ||
|
|
||
| import { ErrorDisplay } from "@/components/shared/ErrorDisplay"; | ||
| import { getBugsnagConfig } from "@/services/errorManagement/bugsnag"; | ||
|
|
||
| interface ErrorHandlerProps { | ||
| error: unknown; | ||
| errorType: "app_error_boundary" | "router_error"; | ||
| resetErrorBoundary?: () => void; | ||
| onGoHome?: () => void; | ||
| } | ||
|
|
||
| /** | ||
| * Unified error handler component used for both React Error Boundaries and Router errors. | ||
| * Automatically reports errors to Bugsnag and provides a user-friendly error display. | ||
| */ | ||
| export const ErrorHandler = ({ | ||
| error, | ||
| errorType, | ||
| resetErrorBoundary, | ||
| onGoHome, | ||
| }: ErrorHandlerProps) => { | ||
| useEffect(() => { | ||
| const config = getBugsnagConfig(); | ||
|
|
||
| if (config.enabled && error instanceof Error) { | ||
| Bugsnag.notify(error, (event) => { | ||
| event.addMetadata("error_handler", { | ||
| type: errorType, | ||
| pathname: window.location.pathname, | ||
| }); | ||
| }); | ||
| } | ||
| }, [error, errorType]); | ||
|
|
||
| const handleRefresh = () => { | ||
| // Reset error boundary if available before reloading | ||
| resetErrorBoundary?.(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this used for? seems like its only used in this file. lets remove it if we don't need it. |
||
| window.location.reload(); | ||
| }; | ||
|
|
||
| const handleGoHomeClick = () => { | ||
| // Reset error boundary if available | ||
| resetErrorBoundary?.(); | ||
|
|
||
| // Use custom handler if provided, otherwise use window.location | ||
| if (onGoHome) { | ||
| onGoHome(); | ||
| } else { | ||
| window.location.href = "/"; | ||
| } | ||
|
Comment on lines
+48
to
+52
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can just default onGoHome = () => window.location.href = "/";NIT: Do we rename this to something else? |
||
| }; | ||
|
|
||
| return ( | ||
| <ErrorDisplay | ||
| error={error} | ||
| onRefresh={handleRefresh} | ||
| onGoHome={handleGoHomeClick} | ||
| /> | ||
| ); | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we remove this magic string?