Skip to content

Commit cd83ed9

Browse files
authored
refactor: error page fallback (#1765)
Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent 2c04f82 commit cd83ed9

File tree

4 files changed

+177
-8
lines changed

4 files changed

+177
-8
lines changed

src/renderer/components/Oops.test.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { render } from '@testing-library/react';
22
import { Oops } from './Oops';
33

44
describe('renderer/components/Oops.tsx', () => {
5-
it('should render itself & its children', () => {
5+
it('should render itself & its children - specified error', () => {
66
const mockError = {
77
title: 'Error title',
88
descriptions: ['Error description'],
@@ -12,4 +12,10 @@ describe('renderer/components/Oops.tsx', () => {
1212

1313
expect(tree).toMatchSnapshot();
1414
});
15+
16+
it('should render itself & its children - fallback to unknown error', () => {
17+
const tree = render(<Oops error={null} />);
18+
19+
expect(tree).toMatchSnapshot();
20+
});
1521
});

src/renderer/components/Oops.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type FC, useMemo } from 'react';
22

33
import type { GitifyError } from '../types';
4+
import { Errors } from '../utils/errors';
45
import { EmojiSplash } from './layout/EmojiSplash';
56

67
interface IOops {
@@ -9,16 +10,18 @@ interface IOops {
910
}
1011

1112
export const Oops: FC<IOops> = ({ error, fullHeight = true }: IOops) => {
13+
const err = error ?? Errors.UNKNOWN;
14+
1215
const emoji = useMemo(
13-
() => error.emojis[Math.floor(Math.random() * error.emojis.length)],
14-
[error],
16+
() => err.emojis[Math.floor(Math.random() * err.emojis.length)],
17+
[err],
1518
);
1619

1720
return (
1821
<EmojiSplash
1922
emoji={emoji}
20-
heading={error.title}
21-
subHeadings={error.descriptions}
23+
heading={err.title}
24+
subHeadings={err.descriptions}
2225
fullHeight={fullHeight}
2326
/>
2427
);

src/renderer/components/__snapshots__/Oops.test.tsx.snap

Lines changed: 162 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/routes/Notifications.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Oops } from '../components/Oops';
55
import { AccountNotifications } from '../components/notifications/AccountNotifications';
66
import { AppContext } from '../context/App';
77
import { getAccountUUID } from '../utils/auth/utils';
8-
import { Errors } from '../utils/errors';
98
import { getNotificationCount } from '../utils/notifications/notifications';
109

1110
export const NotificationsRoute: FC = () => {
@@ -28,7 +27,7 @@ export const NotificationsRoute: FC = () => {
2827
);
2928

3029
if (status === 'error') {
31-
return <Oops error={globalError ?? Errors.UNKNOWN} />;
30+
return <Oops error={globalError} />;
3231
}
3332

3433
if (!hasNotifications && hasNoAccountErrors) {

0 commit comments

Comments
 (0)