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 all 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
1 change: 1 addition & 0 deletions frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = {
"jsdoc/require-param": 0,
"jsdoc/require-param-description": 1,
"jsdoc/require-param-name": 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(404) // is supposed to be 404
})
}
)
})
})
47 changes: 42 additions & 5 deletions frontend/package-lock.json

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

6 changes: 5 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@
"devDependencies": {
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"@types/react-router-dom": "^5.3.3",
"@types/history": "^4.7.11",
"@types/scheduler": "^0.23.0",
"@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 All @@ -49,6 +52,7 @@
"i18next-browser-languagedetector": "^7.2.1",
"i18next-http-backend": "^2.5.0",
"react-i18next": "^14.1.0",
"scheduler": "^0.23.0",
"typescript": "^5.2.2",
"vite": "^5.1.7"
}
Expand Down
Binary file added frontend/public/img/error_pigeon.png
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
13 changes: 10 additions & 3 deletions frontend/public/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"home": {
"title": "Homepage"
},
"header": {
"myProjects": "My Projects",
"myCourses": "My Courses",
Expand Down Expand Up @@ -45,6 +42,16 @@
"minutesAgo": "minutes ago",
"justNow": "just now"
},
"error": {
"pageNotFound": "Page Not Found",
"pageNotFoundMessage": "The requested page was not found.",
"forbidden": "Forbidden",
"forbiddenMessage": "You don't have access to this resource.",
"clientError": "Client Error",
"clientErrorMessage": "A client error has occured.",
"serverError": "Server Error",
"serverErrorMessage": "A server error has occured."
},
"projectForm": {
"projectTitle": "Title",
"projectDescription": "Project description",
Expand Down
10 changes: 10 additions & 0 deletions frontend/public/locales/nl/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,15 @@
"hoursAgo": "uur geleden",
"minutesAgo": "minuten geleden",
"justNow": "Zonet"
},
"error": {
"pageNotFound": "Pagina Niet Gevonden",
"pageNotFoundMessage": "De opgevraagde pagina werd niet gevonden.",
"forbidden": "Verboden",
"forbiddenMessage": "Je hebt geen toegang tot deze bron.",
"clientError": "Client Fout",
"clientErrorMessage": "Er is een client fout opgetreden.",
"serverError": "Server Fout",
"serverErrorMessage": "Er is een server fout opgetreden."
}
}
10 changes: 4 additions & 6 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import Layout from "./components/Header/Layout";
import Home from "./pages/home/Home";
import LanguagePath from "./components/LanguagePath";
import ProjectView from "./pages/project/projectView/ProjectView";
import { ErrorBoundary } from "./pages/error/ErrorBoundary.tsx";
import ProjectCreateHome from "./pages/create_project/ProjectCreateHome.tsx";

const router = createBrowserRouter(
createRoutesFromElements(
<Route path="/" element={<Layout />}>
<Route path="/" element={<Layout />} errorElement={<ErrorBoundary />}>
<Route index element={<Home />} />
<Route path=":lang" element={<LanguagePath/>}>
<Route path="home" element={<Home />} />
Expand All @@ -27,8 +28,5 @@ const router = createBrowserRouter(
* @returns - The main application component
*/
export default function App(): React.JSX.Element {
return (
<RouterProvider router={router}>
</RouterProvider>
);
}
return <RouterProvider router={router} />;
}
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 />
</>
);
}
32 changes: 32 additions & 0 deletions frontend/src/pages/error/ErrorBoundary.tsx
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")} />
);
}
}
}
51 changes: 51 additions & 0 deletions frontend/src/pages/error/ErrorPage.tsx
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>
);
}