Skip to content
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

45 Handles errors using react error boundaries #111

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,38 @@ import JsonStoreView from './components/json_store_view'
import MdxTemplateView from './components/mdx_template_view'
import RootLayout from './components/root_layout'
import templatesConfig from './templates/templates_config'
import TemplateEditor from "./components/editor";
import Home from "./components/home";
import JobsView from "./components/jobs_view";
import TemplateEditor from "./components/editor"
import Home from "./components/home"
import JobsView from "./components/jobs_view"
import ErrorElement from "./components/error"

// Routes to be used by React Router, which handles all the
// browser routing within this domain.
const routes = [{
path: "/",
element: <RootLayout><Home/></RootLayout>
element: <RootLayout><Home/></RootLayout>,
errorElement: <ErrorElement/>,
},{
path: "/template_editor",
element: <TemplateEditor />,
errorElement: <ErrorElement/>,
},
].concat(Object.keys(templatesConfig).flatMap(dbName => [{
path: `/app/${dbName}`,
// TODO: Create a component that provides the functionality
// to manage the documents in this DB
element: <RootLayout><div><JobsView dbName={dbName} /></div></RootLayout>,
errorElement: <ErrorElement/>,
},
{
path: `/app/${dbName}/:docId`,
element: <RootLayout><MdxTemplateView dbName={dbName} /></RootLayout>,
errorElement: <ErrorElement/>,
},
{
path: `/app/${dbName}/:docId/json`,
element: <RootLayout><JsonStoreView dbName={dbName} /></RootLayout>,
errorElement: <ErrorElement/>,
}
]))

Expand Down
13 changes: 13 additions & 0 deletions src/components/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react"

const errorElement = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about calling this component RouterErrorElement?

Please add jsDoc documentation for this component. Most important is to explain how it is to be used.

This component should also follow the Typescript pattern of our other components – see home.tsx.

return (
<div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about the following message:

<h1>An Unexpected Error Has Occurred</h1>
<p>
    To recover, try the following:
    <ul>
        <li>Refresh the browser</li>
        <li>Go back to the <a href="/">home screen</a></li>
    </ul>
</p>

When we have a support email address, we can add another bullet about contacting us.

<span>Oh no!</span>
<span>It seems that we have encountered an error, please refresh and try again</span>
<span>If the problem persists, please contact us</span>
</div>
)
}

export default errorElement