-
Notifications
You must be signed in to change notification settings - Fork 1
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
error pages #93
error pages #93
Changes from 12 commits
257eac3
51f8240
044f6d7
983c721
5c51757
2e0f86e
3b7cb88
9a2b0a5
20c0d8d
d8034f9
a47932e
32e501e
e1a9140
0c632c0
8471fd6
8d5178c
246cec7
8baecd8
df75fd5
28066ff
04c19cb
775b6b4
7a6c25c
7634577
3cc8257
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.gt(299) // is supposed to be 404 | ||
}) | ||
} | ||
) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice, just make sure there is no copy right on this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The image is free of copyright. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
import { BrowserRouter, Route, Routes } from "react-router-dom"; | ||
import Home from "./pages/home/Home"; | ||
import { Header } from "./components/Header/Header"; | ||
import { RouterProvider, createBrowserRouter } from "react-router-dom"; | ||
import Home from "./pages/home/Home.tsx"; | ||
import { Layout } from "./Layout.tsx"; | ||
import { ErrorBoundary } from "./pages/error/ErrorBoundary.tsx"; | ||
|
||
const router = createBrowserRouter([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to solve this without this, you are removing previous structure which all other branches rely on |
||
{ | ||
path: "/", | ||
Component: Layout , | ||
errorElement: <ErrorBoundary />, | ||
children: [ | ||
{ | ||
index: true, | ||
Component: Home | ||
} | ||
] | ||
} | ||
]); | ||
|
||
/** | ||
* This component is the main application component that will be rendered by the ReactDOM. | ||
* @returns - The main application component | ||
* @returns The main application component | ||
*/ | ||
function App(): JSX.Element { | ||
return ( | ||
<BrowserRouter> | ||
<Header /> | ||
<Routes> | ||
<Route index element={<Home />} /> | ||
</Routes> | ||
</BrowserRouter> | ||
); | ||
export default function App(): React.JSX.Element { | ||
return <RouterProvider router={router} />; | ||
} | ||
|
||
export default App; |
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 /> | ||
</> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useRouteError, isRouteErrorResponse } from "react-router-dom"; | ||
import { ErrorPage } from "./ErrorPage.tsx"; | ||
|
||
/** | ||
* 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(); | ||
if (isRouteErrorResponse(error)) { | ||
if (error.status == 404) { | ||
return ( | ||
<ErrorPage statusCode={"404"} statusTitle={"Page Not Found"} message={"page_not_found_message"} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very confusing, the prop name doesn't do what it says at all. A key is not a message. translate it there instead of passing the message There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
); | ||
} | ||
if (error.status == 403) { | ||
return ( | ||
<ErrorPage statusCode={"403"} statusTitle={"Forbidden"} message={"forbidden_message"} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
); | ||
} | ||
if (error.status >= 500 && error.status <= 599) { | ||
return ( | ||
<ErrorPage statusCode={error.statusText} statusTitle={"Server Error"} message={"server_error_message"} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Grid, Typography } from "@mui/material"; | ||
import { Image } from "mui-image"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
/** | ||
* 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 } | ||
): JSX.Element { | ||
|
||
const { t } = useTranslation(); | ||
|
||
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> | ||
<Image src="/error_pigeon.png" height="20vh" alt="icon" /> | ||
</Grid> | ||
</Grid> | ||
</Grid> | ||
<Grid item> | ||
<Typography variant="h3"> | ||
{ statusTitle } | ||
</Typography> | ||
</Grid> | ||
<Grid item> | ||
<Typography variant="body1"> | ||
{ t(message) } | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we expecting 299?