forked from reactplay/react-play
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [Feature reactplay#498]: Add Error Boundaries (reactplay#514)
* ✨ [Feature reactplay#498]: Add Error Boundaries * Minor change * Correct formatting * Addressing review comments Co-authored-by: Tapas Adhikary <[email protected]>
- Loading branch information
1 parent
bac2211
commit e22b0cd
Showing
5 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from "react"; | ||
import { ErrorBoundary } from "react-error-boundary"; | ||
import ErrorFallback from "./ErrorFallback"; | ||
|
||
const ErrorBoundry = ({ children }) => { | ||
const onErrorReset = () => { | ||
/** | ||
* Had to do this because we have placed the ErrorBoundary at the top level | ||
* and we can't use the react-router hooks outside of the Router | ||
*/ | ||
window.location.href = "/"; | ||
}; | ||
|
||
return ( | ||
<ErrorBoundary FallbackComponent={ErrorFallback} onReset={onErrorReset}> | ||
{children} | ||
</ErrorBoundary> | ||
); | ||
}; | ||
|
||
export default ErrorBoundry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from "react"; | ||
|
||
import { ReactComponent as ImageOops } from "images/img-oops.svg"; | ||
import { Button, Typography } from "@mui/material"; | ||
import { makeStyles } from "@mui/styles"; | ||
|
||
const useStyle = makeStyles({ | ||
Typography: { | ||
margin: "8px 0px", | ||
fontWeight: 600, | ||
}, | ||
Button: { | ||
background: "#00f2fe", | ||
color: "#ffffff", | ||
"&:hover": { | ||
background: "#00f2fe", | ||
color: "#ffffff", | ||
}, | ||
}, | ||
}); | ||
|
||
const ErrorFallback = ({ error, resetErrorBoundary }) => { | ||
const classes = useStyle(); | ||
|
||
return ( | ||
<div className="error-boundary-fallback"> | ||
<ImageOops className="error-boundary-image" /> | ||
<Typography className={classes.Typography}> | ||
Something went wrong! | ||
</Typography> | ||
<Typography className={classes.Typography}>{error.message}</Typography> | ||
<Button | ||
className={classes.Button} | ||
variant="contained" | ||
onClick={resetErrorBoundary} | ||
> | ||
Go back | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ErrorFallback; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters