fix: implement Global Error Boundary to prevent application crashes#246
fix: implement Global Error Boundary to prevent application crashes#246Priyasharma620064 wants to merge 1 commit into
Conversation
Signed-off-by: Priya Sharma <priyasharma1001a@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Code Review
This pull request introduces a GlobalErrorBoundary component to provide a graceful fallback UI when uncaught errors occur in the frontend. The boundary is integrated into the main App component, wrapping the entire application structure. Review feedback suggests moving the GlobalErrorBoundary inside the ThemeProvider to ensure the fallback UI respects the application's custom theme and recommends externalizing hardcoded strings to support future internationalization.
| <GlobalErrorBoundary> | ||
| <ThemeProvider theme={theme}> | ||
| <Router> | ||
| <Routes> | ||
| <Route path="/" element={<Layout />}> | ||
| <Route | ||
| index | ||
| element={<Navigate to="/dashboard" replace />} | ||
| /> | ||
| <Route path="dashboard" element={<Dashboard />} /> | ||
| <Route path="jobs" element={<Jobs />} /> | ||
| <Route path="queues" element={<Queues />} /> | ||
| <Route path="pods" element={<Pods />} /> | ||
| <Route path="podgroups" element={<PodGroups />} /> | ||
| </Route> | ||
| </Routes> | ||
| </Router> | ||
| </ThemeProvider> | ||
| </GlobalErrorBoundary> |
There was a problem hiding this comment.
The GlobalErrorBoundary is currently wrapping the ThemeProvider. When an error occurs and the fallback UI is rendered, it will be outside the theme context, causing Material UI components to use their default styles instead of your custom theme. Moving the error boundary inside the ThemeProvider ensures that the error page maintains visual consistency with the rest of the application.
| <GlobalErrorBoundary> | |
| <ThemeProvider theme={theme}> | |
| <Router> | |
| <Routes> | |
| <Route path="/" element={<Layout />}> | |
| <Route | |
| index | |
| element={<Navigate to="/dashboard" replace />} | |
| /> | |
| <Route path="dashboard" element={<Dashboard />} /> | |
| <Route path="jobs" element={<Jobs />} /> | |
| <Route path="queues" element={<Queues />} /> | |
| <Route path="pods" element={<Pods />} /> | |
| <Route path="podgroups" element={<PodGroups />} /> | |
| </Route> | |
| </Routes> | |
| </Router> | |
| </ThemeProvider> | |
| </GlobalErrorBoundary> | |
| <ThemeProvider theme={theme}> | |
| <GlobalErrorBoundary> | |
| <Router> | |
| <Routes> | |
| <Route path="/" element={<Layout />}> | |
| <Route | |
| index | |
| element={<Navigate to="/dashboard" replace />} | |
| /> | |
| <Route path="dashboard" element={<Dashboard />} /> | |
| <Route path="jobs" element={<Jobs />} /> | |
| <Route path="queues" element={<Queues />} /> | |
| <Route path="pods" element={<Pods />} /> | |
| <Route path="podgroups" element={<PodGroups />} /> | |
| </Route> | |
| </Routes> | |
| </Router> | |
| </GlobalErrorBoundary> | |
| </ThemeProvider> |
| Something went wrong | ||
| </Typography> | ||
| <Typography variant="body1" color="text.secondary" sx={{ mb: 4 }}> | ||
| The dashboard encountered an unexpected error. This might be due to a temporary network issue or invalid data from the cluster. | ||
| </Typography> | ||
|
|
||
| <Button | ||
| variant="contained" | ||
| startIcon={<RefreshIcon />} | ||
| onClick={this.handleReset} | ||
| sx={{ textTransform: "none", px: 4, py: 1 }} | ||
| > | ||
| Reload Dashboard |
Description
while exploring the codebase, I noticed that the dashboard didn't have a 'safety net' for runtime errors. Right now, if a component crashes (like from a bad API response or a data parsing issue), the whole screen just goes white.
I've added a Global Error Boundary to catch these unexpected crashes. Now, instead of a blank screen, users will see a professional 'Something went wrong' page with a quick reload button. This makes the dashboard much more resilient and reliable for production users.
Changes made: