-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Error Boundary with debugging info
- Loading branch information
1 parent
786b03b
commit d610569
Showing
4 changed files
with
170 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,90 @@ | ||
import { | ||
Message, | ||
Icon, | ||
Button, | ||
Image, | ||
Accordion, | ||
} from "semantic-ui-react"; | ||
import { useEffect, useState } from "react"; | ||
|
||
const ErrorScreen = ({ | ||
error, | ||
resetErrorBoundary, | ||
}: { | ||
error: any; | ||
resetErrorBoundary: () => void; | ||
}) => { | ||
const [devInfoOpen, setDevInfoOpen] = useState(false); | ||
|
||
/** | ||
* Setup page & title on load | ||
*/ | ||
useEffect(() => { | ||
document.title = "LibreTexts | Error"; | ||
}, []); | ||
|
||
return ( | ||
<div className="flex flex-col items-center bg-white h-screen w-screen justify-center"> | ||
<div className="flex flex-col items-center justify-center py-4 px-36"> | ||
<Image | ||
src="/libretexts_logo.png" | ||
alt="LibreTexts logo" | ||
className="w-96" | ||
/> | ||
<p className="text-3xl font-semibold mb-8 mt-10 text-center"> | ||
Oops, this page encountered an error. Please refresh to try again. | ||
</p> | ||
<Button | ||
icon | ||
color="blue" | ||
size="big" | ||
className="flex mt-4" | ||
onClick={() => window.location.reload()} | ||
> | ||
<Icon name="refresh" /> Refresh | ||
</Button> | ||
<Accordion styled className="!w-80 mt-24"> | ||
<Accordion.Title | ||
active={devInfoOpen} | ||
index={0} | ||
onClick={() => setDevInfoOpen(!devInfoOpen)} | ||
> | ||
<Icon name="dropdown" /> | ||
Show Debugging Info | ||
</Accordion.Title> | ||
<Accordion.Content active={devInfoOpen}> | ||
{typeof error === "object" && error.message && ( | ||
<Message negative> | ||
<Message.Header>{error.name}</Message.Header> | ||
<p>{error.message}</p> | ||
</Message> | ||
)} | ||
{typeof error === "string" && ( | ||
<Message negative> | ||
<Message.Header>Unknown Error</Message.Header> | ||
<p>{error}</p> | ||
</Message> | ||
)} | ||
{!error && ( | ||
<Message negative> | ||
<Message.Header>Unknown Error</Message.Header> | ||
<p>No error message was provided.</p> | ||
</Message> | ||
)} | ||
</Accordion.Content> | ||
</Accordion> | ||
<Button | ||
icon | ||
size="mini" | ||
className="flex !mt-6" | ||
onClick={() => window.location.assign("https://launchpad.libretexts.org")} | ||
> | ||
<Icon name="location arrow" /> Go To Launchpad | ||
</Button> | ||
|
||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ErrorScreen; |