Skip to content

Commit

Permalink
feature/add-catch-all-route (#223)
Browse files Browse the repository at this point in the history
* Underline Fixed (191)

* ErrorPage.tsx

* Updated ErrorPage to pass lint.

* Updated changes based on To's feedback.

* Updated based on lint.
  • Loading branch information
NA-CA committed May 26, 2022
1 parent 62c6bcf commit c983b9d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/app/App.tsx
Expand Up @@ -16,6 +16,7 @@ import { EventPage } from "../pages/EventPage";
import { EventsPage } from "../pages/EventsPage";
import { PersonPage } from "../pages/PersonPage";
import { PeoplePage } from "../pages/PeoplePage";
import { ErrorPage } from "../pages/ErrorPage";

import { SEARCH_TYPE } from "../pages/SearchPage/types";

Expand Down Expand Up @@ -101,6 +102,7 @@ function App() {
<Route exact path="/people/:id">
<PersonPage />
</Route>
<Route path="*" component={ErrorPage} />
</Switch>
</Main>
<Footer footerLinksSections={municipality.footerLinksSections} />
Expand Down
5 changes: 2 additions & 3 deletions src/containers/FetchDataContainer/FetchDataContainer.tsx
@@ -1,6 +1,7 @@
import React, { FC, ReactNode } from "react";

import { Loader } from "semantic-ui-react";
import ErrorPage from "../../pages/ErrorPage/ErrorPage";

interface FetchDataContainerProps {
isLoading: boolean;
Expand All @@ -17,9 +18,7 @@ const FetchDataContainer: FC<FetchDataContainerProps> = ({
return <Loader active size="massive" />;
}
if (error) {
// Display the error for now.
// TODO: throw the error and catch it with a general error boundary that displays the error page.
return <span>{error.toString()}</span>;
return <ErrorPage error={error} />;
}
return <>{children}</>;
};
Expand Down
23 changes: 23 additions & 0 deletions src/pages/ErrorPage/ErrorPage.tsx
@@ -0,0 +1,23 @@
import React, { FC } from "react";
import { useHistory } from "react-router-dom";

interface ErrorPageProps {
error?: any;
}

const ErrorPage: FC<ErrorPageProps> = ({ error }: ErrorPageProps) => {
const history = useHistory();
const errorText = error ? error.toString() : "";

return (
<div>
<h1 className="mzp-u-title-sm">Sorry, we can’t find that page.</h1>
<p>{errorText}</p>
<button className="mzp-c-button mzp-t-secondary mzp-t-md" onClick={() => history.goBack()}>
Back
</button>
</div>
);
};

export default ErrorPage;
1 change: 1 addition & 0 deletions src/pages/ErrorPage/index.ts
@@ -0,0 +1 @@
export { default as ErrorPage } from "./ErrorPage";

0 comments on commit c983b9d

Please sign in to comment.