11import React from 'react' ;
22import { Grid , Paper } from '@mui/material' ;
3- import { Link } from 'react-router-dom' ;
3+ import { Link , useLocation } from 'react-router-dom' ;
44import classnames from 'classnames' ;
55
66// styles
@@ -12,8 +12,28 @@ import { Button, Typography } from '../../components/Wrappers';
1212// logo
1313import logo from './logo.svg' ;
1414
15- export default function Error ( ) {
15+ const ERROR_CONTENT = {
16+ 403 : {
17+ title : 'Access denied' ,
18+ description : "You don't have permissions to view this page" ,
19+ } ,
20+ 404 : {
21+ title : "Page doesn't exist" ,
22+ description : "Looks like the page you're looking for no longer exists" ,
23+ } ,
24+ 500 : {
25+ title : 'Server error' ,
26+ description : 'Something went wrong while processing your request' ,
27+ } ,
28+ } ;
29+
30+ export default function Error ( { code } ) {
1631 let classes = useStyles ( ) ;
32+ const location = useLocation ( ) ;
33+ const queryParams = new URLSearchParams ( location . search ) ;
34+ const queryCode = Number ( queryParams . get ( 'code' ) ) ;
35+ const errorCode = Number ( code ) || queryCode || 404 ;
36+ const content = ERROR_CONTENT [ errorCode ] || ERROR_CONTENT [ 404 ] ;
1737
1838 return (
1939 < Grid container className = { classes . container } >
@@ -29,18 +49,18 @@ export default function Error() {
2949 color = 'primary'
3050 className = { classnames ( classes . textRow , classes . errorCode ) }
3151 >
32- 404
52+ { errorCode }
3353 </ Typography >
3454 < Typography variant = 'h5' color = 'primary' className = { classes . textRow } >
35- Oops. Looks like the page you're looking for no longer exists
55+ { content . title }
3656 </ Typography >
3757 < Typography
3858 variant = 'h6'
3959 color = 'text'
4060 colorBrightness = 'hint'
4161 className = { classnames ( classes . textRow , classes . safetyText ) }
4262 >
43- But we're here to bring you back to safety
63+ { content . description }
4464 </ Typography >
4565 < Button
4666 variant = 'contained'
0 commit comments