Skip to content

Commit 3dbfaa0

Browse files
authored
4558 - error handling (#4600)
1 parent dee9575 commit 3dbfaa0

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

ui/src/router.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ProjectDetails } from './features/project/project-details.component';
1414
import { Layout } from './layout';
1515
import { Dataset } from './routes/dataset/dataset.component';
1616
import { SelectedDataProvider } from './routes/dataset/provider';
17+
import { ErrorPage } from './routes/error-page/error-page';
1718
import { Inference } from './routes/inference/inference';
1819
import { Labels } from './routes/labels/labels';
1920
import { Models } from './routes/models/models';
@@ -60,7 +61,7 @@ export const router = createBrowserRouter([
6061
<Layout />
6162
</Suspense>
6263
),
63-
errorElement: <div>Oh no</div>,
64+
errorElement: <ErrorPage />,
6465
children: [
6566
{
6667
index: true,
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (C) 2025 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { Button, Heading, IllustratedMessage, View } from '@geti/ui';
5+
import { NotFound } from '@geti/ui/icons';
6+
import { isRouteErrorResponse, useRouteError } from 'react-router';
7+
8+
import { paths } from '../../router';
9+
import { redirectTo } from '../utils';
10+
11+
const useErrorMessage = () => {
12+
const error = useRouteError();
13+
14+
if (isRouteErrorResponse(error)) {
15+
if (error.status === 400) {
16+
return 'The server cannot or will not process the current request.';
17+
}
18+
19+
if (error.status === 403) {
20+
return 'You do not have permission to access this page.';
21+
}
22+
23+
if (error.status === 404) {
24+
return "This page doesn't exist!";
25+
}
26+
27+
if (error.status === 401) {
28+
return "You aren't authorized to see this";
29+
}
30+
31+
if (error.status === 500) {
32+
return 'The server encountered an error and could not complete your request.';
33+
}
34+
35+
if (error.status === 503) {
36+
return 'Looks like our API is down';
37+
}
38+
}
39+
40+
if (error instanceof TypeError) {
41+
return error.message;
42+
}
43+
44+
return 'An unknown error occurred';
45+
};
46+
47+
export const ErrorPage = (): JSX.Element => {
48+
const message = useErrorMessage();
49+
50+
return (
51+
<View height={'100vh'}>
52+
<IllustratedMessage>
53+
<NotFound />
54+
<Heading>{message}</Heading>
55+
56+
<Button
57+
variant={'accent'}
58+
marginTop={'size-200'}
59+
onPress={() => {
60+
redirectTo(paths.root({}));
61+
}}
62+
>
63+
Go back to home page
64+
</Button>
65+
</IllustratedMessage>
66+
</View>
67+
);
68+
};

ui/src/routes/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright (C) 2025 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
export const redirectTo = (url: string): void => {
5+
window.location.href = url;
6+
};

0 commit comments

Comments
 (0)