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

error pages #93

Merged
merged 25 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
257eac3
initial draft for error pages
Matisse-Sulzer Mar 13, 2024
51f8240
indentation fixed
Matisse-Sulzer Mar 13, 2024
044f6d7
docs
Matisse-Sulzer Mar 13, 2024
983c721
error pages v1
Matisse-Sulzer Mar 14, 2024
5c51757
indentation fixed
Matisse-Sulzer Mar 14, 2024
2e0f86e
layout adjusted, using RouterProvider instead of BrowserRouter to ren…
Matisse-Sulzer Mar 21, 2024
3b7cb88
linter
Matisse-Sulzer Mar 21, 2024
9a2b0a5
documentation
Matisse-Sulzer Mar 28, 2024
20c0d8d
Merge branch 'development' into frontend/enhancement/error_pages
Matisse-Sulzer Mar 28, 2024
d8034f9
Merge branch 'development' of https://github.com/SELab-2/UGent-3 into…
Matisse-Sulzer Mar 28, 2024
a47932e
Merge branch 'frontend/enhancement/error_pages' of https://github.com…
Matisse-Sulzer Mar 28, 2024
32e501e
linter error parameters
Matisse-Sulzer Mar 28, 2024
e1a9140
Merge branch 'development' into frontend/enhancement/error_pages
Matisse-Sulzer Mar 31, 2024
0c632c0
Added i18n, changed general structure of App component and got rid of…
Matisse-Sulzer Apr 13, 2024
8471fd6
Merge branch 'development' into frontend/enhancement/error_pages
Matisse-Sulzer Apr 13, 2024
8d5178c
linting, package-lock.json fix
Matisse-Sulzer Apr 13, 2024
246cec7
package file
Matisse-Sulzer Apr 13, 2024
8baecd8
changes to paramters in ErrorPage.tsx
Matisse-Sulzer Apr 14, 2024
df75fd5
Merge branch 'development' into frontend/enhancement/error_pages
Matisse-Sulzer Apr 14, 2024
28066ff
Merge branch 'development' into frontend/enhancement/error_pages
Matisse-Sulzer Apr 15, 2024
04c19cb
use of keyPrefix
Matisse-Sulzer Apr 18, 2024
775b6b4
Merge branch 'development' into frontend/enhancement/error_pages
Matisse-Sulzer Apr 18, 2024
7a6c25c
Merge branch 'development' into frontend/enhancement/error_pages
Matisse-Sulzer Apr 18, 2024
7634577
keyPrefix
Matisse-Sulzer Apr 18, 2024
3cc8257
fix
Matisse-Sulzer Apr 18, 2024
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
6 changes: 3 additions & 3 deletions frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
"jsdoc/check-access": 1,
"tsdoc/syntax": "warn",
"jsdoc/check-alignment": 1,
"jsdoc/check-param-names": 1,
"jsdoc/check-param-names": 0,
"jsdoc/check-property-names": 1,
"jsdoc/check-tag-names": 1,
"jsdoc/check-types": 1,
Expand All @@ -37,10 +37,10 @@ module.exports = {
"jsdoc/no-multi-asterisks": 1,
"jsdoc/no-undefined-types": 1,
"jsdoc/require-jsdoc": 1,
"jsdoc/require-param": 1,
"jsdoc/require-param": 0,
"jsdoc/require-param-description": 1,
"jsdoc/require-param-name": 1,
"jsdoc/require-param-type": 1,
"jsdoc/require-param-type": 0,
"jsdoc/require-property": 1,
"jsdoc/require-property-description": 1,
"jsdoc/require-property-name": 1,
Expand Down
16 changes: 16 additions & 0 deletions frontend/cypress/e2e/ErrorPage.cy.tsx
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
Copy link
Contributor

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?

})
}
)
})
})
90 changes: 71 additions & 19 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@
"@mui/icons-material": "^5.15.10",
"@mui/material": "^5.15.10",
"@mui/styled-engine-sc": "^6.0.0-alpha.16",
"@types/mui-image": "^1.0.5",
"mui-image": "^1.0.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.1",
"react-i18next": "^14.1.0",
"react-router-dom": "^6.22.3",
"styled-components": "^6.1.8"
},
"devDependencies": {
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"@types/react-router-dom": "^5.3.3",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vitejs/plugin-react": "^4.2.1",
"cypress": "^13.6.4",
"cypress": "^13.7.0",
"eslint": "^8.56.0",
"eslint-plugin-jsdoc": "^48.1.0",
"eslint-plugin-react-hooks": "^4.6.0",
Expand Down
Binary file added frontend/public/error_pigeon.png
Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice, just make sure there is no copy right on this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The image is free of copyright. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 21 additions & 15 deletions frontend/src/App.tsx
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([
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
15 changes: 15 additions & 0 deletions frontend/src/Layout.tsx
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 />
</>
);
}
27 changes: 27 additions & 0 deletions frontend/src/pages/error/ErrorBoundary.tsx
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"} />
Copy link
Contributor

Choose a reason for hiding this comment

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

  • statusTitle doesn't use i18n
  • message seems like it should be a variable, doesn't use i18n and doesn't conform TS camelCase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

message is just a string that is used as a key to translate via i18n.

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"} />
Copy link
Contributor

Choose a reason for hiding this comment

The 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"} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

);
}
}
}
56 changes: 56 additions & 0 deletions frontend/src/pages/error/ErrorPage.tsx
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>
);
}