-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hotfix: 잘못된 id의 상점 접근 시 에러 처리 및 슬랙 오류 호출 시점 변경
- Loading branch information
1 parent
681bc3f
commit 2c3939f
Showing
5 changed files
with
118 additions
and
17 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
22 changes: 22 additions & 0 deletions
22
src/pages/Store/components/StoreDetailBoundary/StoreDetailBoundary.module.scss
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,22 @@ | ||
.container { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column; | ||
height: 60vh; | ||
} | ||
|
||
.button { | ||
color: #fff; | ||
font-size: 15px; | ||
text-decoration: none; | ||
cursor: pointer; | ||
width: 88px; | ||
height: 36px; | ||
box-sizing: border-box; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: #175c8e; | ||
margin-top: 25px; | ||
} |
68 changes: 68 additions & 0 deletions
68
src/pages/Store/components/StoreDetailBoundary/StoreDetailBoundary.tsx
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,68 @@ | ||
import React, { ErrorInfo } from 'react'; | ||
import { AxiosError } from 'axios'; | ||
import showToast from 'utils/ts/showToast'; | ||
import { isKoinError, sendClientError } from '@bcsdlab/koin'; | ||
import styles from './StoreDetailBoundary.module.scss'; | ||
|
||
interface Props { | ||
onErrorClick: () => void; | ||
children: React.ReactNode; | ||
} | ||
|
||
interface State { | ||
hasError: boolean; | ||
status?: number; | ||
} | ||
|
||
function isAxiosError(error: AxiosError<any, any> | Error): error is AxiosError<any, any> { | ||
return ('response' in error); | ||
} | ||
|
||
export default class StoreDetailBoundary extends React.Component<Props, State> { | ||
constructor(props: Props) { | ||
super(props); | ||
this.state = { hasError: false }; | ||
} | ||
|
||
// 이후에 사용시 해제 | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
static getDerivedStateFromError(error: Error) { | ||
if (isKoinError(error) || isAxiosError(error)) { | ||
return { hasError: true, status: error.status }; | ||
} | ||
return { hasError: true }; | ||
} | ||
|
||
// 이후에 사용시 해제 | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
componentDidCatch(error: Error, __: ErrorInfo) { | ||
showToast('error', error.message); | ||
sendClientError(error); | ||
} | ||
|
||
render() { | ||
const { children, onErrorClick } = this.props; | ||
const { hasError, status } = this.state; | ||
|
||
if (hasError && status === 404) { | ||
return ( | ||
<div className={styles.container}> | ||
<h1>존재하지 않는 상점입니다.</h1> | ||
<button | ||
className={styles.button} | ||
type="button" | ||
onClick={onErrorClick} | ||
> | ||
상점 목록 | ||
</button> | ||
</div> | ||
); | ||
} | ||
|
||
if (hasError) { | ||
return <div className={styles.container}>오류가 발생했습니다</div>; | ||
} | ||
|
||
return children; | ||
} | ||
} |