-
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.
feat(web/components): Error, react-query가 포함된 ErrorBoundary 컴포넌트 추가 (#42
) * chore(eslint-config-favolink): 함수 호출 간의 공백 규칙 추가 * feat(web/components): react-query를 감싸는 ErrorBoundary 추가 * feat(web/components): 임시 Error 컴포넌트 추가
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { AxiosError } from 'axios'; | ||
import type { FallbackProps } from 'react-error-boundary'; | ||
import * as styles from './styles.css'; | ||
|
||
type ErrorProps = Omit<FallbackProps, 'error'> & { | ||
error: AxiosError; | ||
}; | ||
|
||
export default function Error(props: ErrorProps) { | ||
const { resetErrorBoundary, error } = props; | ||
|
||
return ( | ||
<div className={styles.center}> | ||
<h1 className={styles.title}>{error.response?.status}</h1> | ||
<p className={styles.description}>{error.message}</p> | ||
<button | ||
className={styles.button} | ||
onClick={() => { | ||
resetErrorBoundary(); | ||
}} | ||
> | ||
다시 시도 | ||
</button> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { style } from '@vanilla-extract/css'; | ||
|
||
export const container = style({ | ||
height: '100vh', | ||
}); | ||
|
||
export const h1 = style({ | ||
fontWeight: 'bold', | ||
fontSize: 28, | ||
lineHeight: '39px', | ||
}); | ||
|
||
export const normalFont = style({ | ||
color: 'black', | ||
fontSize: 'medium', | ||
}); | ||
|
||
export const center = style([ | ||
container, | ||
{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
gap: 10, | ||
}, | ||
]); | ||
|
||
export const baseButton = style({ | ||
padding: '0.5rem', | ||
outline: 'none', | ||
border: 'unset', | ||
borderRadius: 10, | ||
backgroundColor: 'lightgray', | ||
}); | ||
|
||
export const title = style([ | ||
h1, | ||
{ | ||
color: 'black', | ||
}, | ||
]); | ||
|
||
export const button = style([baseButton, normalFont]); | ||
|
||
export const description = style([normalFont]); |
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,19 @@ | ||
import { QueryErrorResetBoundary } from '@tanstack/react-query'; | ||
import { | ||
ErrorBoundary as ReactErrorBoundary, | ||
type ErrorBoundaryProps as ReactErrorBoundaryProps, | ||
} from 'react-error-boundary'; | ||
|
||
export default function ErrorBoundary(props: ReactErrorBoundaryProps) { | ||
const { children, ...restProps } = props; | ||
|
||
return ( | ||
<QueryErrorResetBoundary> | ||
{({ reset }) => ( | ||
<ReactErrorBoundary {...restProps} onReset={reset}> | ||
{children} | ||
</ReactErrorBoundary> | ||
)} | ||
</QueryErrorResetBoundary> | ||
); | ||
} |
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