-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 메인페이지 에러바운더리 적용 #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
| "use client"; | ||
|
|
||
| import { RefreshCw } from "lucide-react"; | ||
| import React, { Component, ErrorInfo, ReactNode } from "react"; | ||
|
|
||
| interface ErrorBoundaryProps { | ||
| children: ReactNode; | ||
| errorMessage?: string; | ||
| description?: string; | ||
| className?: string; | ||
| } | ||
|
|
||
| interface ErrorBoundaryState { | ||
| hasError: boolean; | ||
| } | ||
|
|
||
| class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> { | ||
| constructor(props: ErrorBoundaryProps) { | ||
| super(props); | ||
| this.state = { hasError: false }; | ||
| } | ||
|
|
||
| static getDerivedStateFromError(): ErrorBoundaryState { | ||
| return { hasError: true }; | ||
| } | ||
|
|
||
| componentDidCatch(error: Error, errorInfo: ErrorInfo): void { | ||
| console.error("Error Boundary caught an error:", error, errorInfo); //eslint-disable-line | ||
| } | ||
|
|
||
| handleRefresh = () => { | ||
| this.setState({ hasError: false }); | ||
| }; | ||
|
|
||
| render(): ReactNode { | ||
| const { hasError } = this.state; | ||
| if (hasError) { | ||
| const { | ||
| errorMessage = "문제가 발생했습니다", | ||
| description = "새로고침을 통해 다시 시도해 주세요.", | ||
| className = "", | ||
| } = this.props; | ||
|
|
||
| return ( | ||
| <div | ||
| className={`flex flex-col items-center justify-center p-16 text-center ${className}`} | ||
| > | ||
| <div className="mb-8 text-red-500">⚠️</div> | ||
| <h3 className="mb-4 text-18-700">{errorMessage}</h3> | ||
| <p className="mb-6 text-14-400 text-gray-600">{description}</p> | ||
| <button | ||
| type="button" | ||
| onClick={this.handleRefresh} | ||
| className="inline-flex items-center gap-2 rounded-md bg-blue-500 px-4 py-2 text-14-600 text-white hover:bg-blue-600 active:bg-blue-700" | ||
| > | ||
| <RefreshCw size={16} /> | ||
| <span>새로고침</span> | ||
| </button> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| const { children } = this.props; | ||
| return children; | ||
| } | ||
| } | ||
|
|
||
| export default ErrorBoundary; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
에러 로깅 개선이 필요합니다
현재 콘솔 로그만 사용하고 있는데, 프로덕션 환경에서는 에러 추적 서비스(예: Sentry)를 활용하는 것이 좋습니다.
componentDidCatch(error: Error, errorInfo: ErrorInfo): void { - console.error("Error Boundary caught an error:", error, errorInfo); //eslint-disable-line + // TODO: Sentry 또는 다른 에러 추적 서비스 연동 + if (process.env.NODE_ENV === 'production') { + // captureException(error, { extra: errorInfo }); + } else { + console.error("Error Boundary caught an error:", error, errorInfo); + } }