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

feature/add-catch-all-route #223

Merged
merged 6 commits into from May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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";