-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial draft for error pages * indentation fixed * docs * error pages v1 * indentation fixed * layout adjusted, using RouterProvider instead of BrowserRouter to render errors correctly, tests added * linter * documentation * linter error parameters * Added i18n, changed general structure of App component and got rid of fade animation for the image * linting, package-lock.json fix * package file * changes to paramters in ErrorPage.tsx * use of keyPrefix * keyPrefix * fix
- Loading branch information
1 parent
9fd38a5
commit d9cd5f8
Showing
12 changed files
with
186 additions
and
15 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,16 @@ | ||
describe('Error page test', () => { | ||
it('Error page should load appropriately', () => { | ||
expect( | ||
() => { | ||
cy.request({ | ||
method: 'POST', | ||
path: '**', | ||
body: {name: "fail"}, | ||
failOnStatusCode: false | ||
}).then(response => { | ||
expect(response.status).to.be(404) // is supposed to be 404 | ||
}) | ||
} | ||
) | ||
}) | ||
}) |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
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
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,15 @@ | ||
import { Outlet } from "react-router-dom"; | ||
import { Header } from "./components/Header/Header.tsx"; | ||
|
||
/** | ||
* Basic layout component that will be used on all routes. | ||
* @returns The Layout component | ||
*/ | ||
export function Layout(): JSX.Element { | ||
return ( | ||
<> | ||
<Header /> | ||
<Outlet /> | ||
</> | ||
); | ||
} |
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,32 @@ | ||
import { useRouteError, isRouteErrorResponse } from "react-router-dom"; | ||
import { ErrorPage } from "./ErrorPage.tsx"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
/** | ||
* This component will render the ErrorPage component with the appropriate data when an error occurs. | ||
* @returns The ErrorBoundary component | ||
*/ | ||
export function ErrorBoundary() { | ||
const error = useRouteError(); | ||
const { t } = useTranslation('translation', { keyPrefix: 'error' }); | ||
|
||
if (isRouteErrorResponse(error)) { | ||
if (error.status == 404) { | ||
return ( | ||
<ErrorPage statusCode={"404"} statusTitle={t("pageNotFound")} message={t("pageNotFoundMessage")} /> | ||
); | ||
} else if (error.status == 403) { | ||
return ( | ||
<ErrorPage statusCode={"403"} statusTitle={t("forbidden")} message={t("forbiddenMessage")} /> | ||
); | ||
} else if (error.status >= 400 && error.status <= 499) { | ||
return ( | ||
<ErrorPage statusCode={error.statusText} statusTitle={t("clientError")} message={t("clientErrorMessage")} /> | ||
); | ||
} else if (error.status >= 500 && error.status <= 599) { | ||
return ( | ||
<ErrorPage statusCode={error.statusText} statusTitle={t("serverError")} message={t("serverErrorMessage")} /> | ||
); | ||
} | ||
} | ||
} |
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,51 @@ | ||
import { Grid, Typography } from "@mui/material"; | ||
|
||
/** | ||
* This component will be rendered when an error occurs. | ||
* @param statusCode - The status code of the error | ||
* @param statusTitle - The name of the error | ||
* @param message - Additional information about the error | ||
* @returns The ErrorPage component | ||
*/ | ||
export function ErrorPage( | ||
{ statusCode, statusTitle, message }: { statusCode: string, statusTitle: string, message: string } | ||
): React.JSX.Element { | ||
return ( | ||
<Grid | ||
container | ||
justifyContent="center" | ||
alignItems="center" | ||
direction="column" | ||
sx={{ minHeight: "100vh" }} | ||
spacing={2} | ||
> | ||
<Grid item> | ||
<Grid | ||
container | ||
justifyContent="center" | ||
alignItems="center" | ||
spacing={4} | ||
> | ||
<Grid item> | ||
<Typography variant="h1"> | ||
{ statusCode } | ||
</Typography> | ||
</Grid> | ||
<Grid item> | ||
<img src="/img/error_pigeon.png" height="150vh" alt="icon" /> | ||
</Grid> | ||
</Grid> | ||
</Grid> | ||
<Grid item> | ||
<Typography variant="h3"> | ||
{ statusTitle } | ||
</Typography> | ||
</Grid> | ||
<Grid item> | ||
<Typography variant="body1"> | ||
{ message } | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
); | ||
} |