-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from jbrunton/error-boundaries
feat: error boundaries
- Loading branch information
Showing
10 changed files
with
99 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react' | ||
import { Container, Alert, AlertIcon, AlertTitle, AlertDescription, Box } from '@chakra-ui/react' | ||
import { AxiosError } from 'axios' | ||
import { useRouteError } from 'react-router-dom' | ||
import { HeaderTemplate } from './shared/navigation/molecules/HeaderTemplate' | ||
|
||
export const ErrorPage = () => { | ||
const error = useRouteError() | ||
const { message } = getErrorDetails(error) | ||
return ( | ||
<> | ||
<HeaderTemplate title='Chat Demo' /> | ||
<Container maxWidth='container.lg'> | ||
<Alert status='error' variant='top-accent' height='200px'> | ||
<AlertIcon boxSize='40px' ml='20px' mr='40px' /> | ||
<Box> | ||
<AlertTitle mt={4} mb={1} fontSize='lg'> | ||
Uh oh! | ||
</AlertTitle> | ||
<AlertDescription>{message}</AlertDescription> | ||
</Box> | ||
</Alert> | ||
</Container> | ||
</> | ||
) | ||
} | ||
|
||
type ErrorDetails = { | ||
message: string | ||
} | ||
|
||
const getErrorDetails = (error: unknown): ErrorDetails => { | ||
if (error instanceof AxiosError) { | ||
const serverMessage = error.response?.data.message | ||
if (serverMessage) { | ||
return { | ||
message: serverMessage, | ||
} | ||
} | ||
} | ||
return { | ||
message: 'There was an unknown error. Please try again later', | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
import React from 'react' | ||
import React, { PropsWithChildren } from 'react' | ||
import { Outlet } from 'react-router-dom' | ||
import { Header } from './shared/navigation/organisms/Header' | ||
|
||
export const Layout = () => ( | ||
export const Layout = ({ children }: PropsWithChildren) => ( | ||
<> | ||
<Header /> | ||
<div className='content'> | ||
<Outlet /> | ||
</div> | ||
<div className='content'>{children ?? <Outlet />}</div> | ||
</> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Flex, Heading, Spacer, HStack, IconButton, Icon } from '@chakra-ui/react' | ||
import React, { FC } from 'react' | ||
import { AiOutlineMenu } from 'react-icons/ai' | ||
|
||
type HeaderTemplateProps = { | ||
title: string | ||
onOpen?: () => void | ||
} | ||
|
||
export const HeaderTemplate: FC<HeaderTemplateProps> = ({ title, onOpen }) => ( | ||
<Flex className='header' p='6px' align='center'> | ||
<Heading size={{ base: 'sm', lg: 'md' }} noOfLines={1}> | ||
{title} | ||
</Heading> | ||
<Spacer /> | ||
{onOpen ? ( | ||
<HStack align='center'> | ||
<IconButton variant='ghost' icon={<DrawerIcon />} aria-label={'Open Menu'} onClick={onOpen} /> | ||
</HStack> | ||
) : null} | ||
</Flex> | ||
) | ||
|
||
const DrawerIcon = () => <Icon as={AiOutlineMenu} boxSize={5} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.