-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils의 fetch 함수 리팩터링, ErrorBoundary 구현, query를 이용한 에러핸들링 (#294)
* refactor: (#158) try-catch 구문으로 변경 Co-authored-by: 김영길/KIM YOUNG GIL <Gilpop8663@users.noreply.github.com> Co-authored-by: chsua <chsua@users.noreply.github.com> * feat: (#158) ErrorBoundary 구현 * refactor: (#158) 데이터 생성 시 에러 핸들링 코드 이동
- Loading branch information
1 parent
a57e8c3
commit 726ee59
Showing
7 changed files
with
184 additions
and
103 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
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,39 @@ | ||
import { Component, ErrorInfo, ReactNode } from 'react'; | ||
|
||
interface ErrorBoundaryProps { | ||
children: ReactNode; | ||
fallback: ReactNode; | ||
} | ||
|
||
interface ErrorBoundaryState { | ||
hasError: boolean; | ||
} | ||
|
||
class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> { | ||
#errorMessage = ''; | ||
|
||
constructor(props: ErrorBoundaryProps) { | ||
super(props); | ||
this.state = { hasError: false }; | ||
} | ||
|
||
static getDerivedStateFromError(error: Error) { | ||
return { hasError: true }; | ||
} | ||
|
||
componentDidCatch(error: Error, errorInfo: ErrorInfo) { | ||
// You can also log the error to an error reporting service | ||
window.console.log(error, errorInfo); | ||
this.#errorMessage = error.message; | ||
} | ||
|
||
render() { | ||
if (this.state.hasError) { | ||
return <div>{this.#errorMessage}</div>; | ||
} | ||
|
||
return this.props.children; | ||
} | ||
} | ||
|
||
export default ErrorBoundary; |
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