-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fe/feature/#560 error boundary적용 #564
Merged
The head ref may contain hidden characters: "FE/feature/#560-ErrorBoundary\uC801\uC6A9"
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6df3340
chore: 에러 바운더리 적용하기위해 react-error-boundary 설치
Doosies 5e7939b
style: rootRouter -> router로 변경
Doosies 6707598
feat: 에러 바운더리 적용
Doosies 8df6299
Merge branch 'dev' into FE/feature/#560-ErrorBoundary적용
Doosies 83a6aba
feat: 에러 바운더리 적용
Doosies 3900cfa
feat: socket이 끊기거나, 서버와 연결할 수 없을 때 에러처리 추가
Doosies 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 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.
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 |
---|---|---|
|
@@ -29,6 +29,16 @@ export class SocketManager<T1 extends EventsMap, T2 extends EventsMap> { | |
return; | ||
} | ||
this.#socket = io(this.#url, { path: this.#path, withCredentials }); | ||
|
||
this.socket?.on('disconnect', () => { | ||
alert('서버와 연결이 끊겼습니다. 메인 페이지로 이동합니다.'); | ||
window.location.href = '/'; | ||
}); | ||
|
||
this.socket?.on('connect_error', () => { | ||
alert('서버와 연결할 수 없습니다. 메인 페이지로 이동합니다.'); | ||
window.location.href = '/'; | ||
}); | ||
Comment on lines
+33
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍👍👍 |
||
} | ||
|
||
disconnect() { | ||
|
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,41 @@ | ||
import { useQueryErrorResetBoundary } from '@tanstack/react-query'; | ||
import { isAxiosError } from 'axios'; | ||
import { ErrorBoundary, FallbackProps } from 'react-error-boundary'; | ||
|
||
import { SomethingWrongErrorPage } from '@pages/ErrorPage'; | ||
|
||
const APIErrorFallback = ({ error }: FallbackProps) => { | ||
if ( | ||
isAxiosError<{ | ||
errorCode: string; | ||
message: string; | ||
}>(error) | ||
) { | ||
const responseBody = error.response?.data; | ||
|
||
// TODO: 에러코드 정의되면 여기서 에러 코드에 따른 작업을 해줘야함. | ||
switch (responseBody?.errorCode) { | ||
} | ||
|
||
// 에러 코드에 따른 작업 처리후 에러 페이지로 이동 | ||
return <SomethingWrongErrorPage />; | ||
} else { | ||
// 그 외의 에러의 경우 상단 바운더리에서 처리 | ||
throw error; | ||
} | ||
}; | ||
|
||
export function APIErrorBoundary({ children }: { children: React.ReactNode }) { | ||
const { reset } = useQueryErrorResetBoundary(); | ||
|
||
return ( | ||
<ErrorBoundary | ||
FallbackComponent={APIErrorFallback} | ||
onReset={reset} | ||
> | ||
{children} | ||
</ErrorBoundary> | ||
); | ||
} | ||
|
||
export default APIErrorBoundary; |
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,20 @@ | ||
import { useQueryErrorResetBoundary } from '@tanstack/react-query'; | ||
import type { PropsWithChildren } from 'react'; | ||
import { ErrorBoundary } from 'react-error-boundary'; | ||
|
||
import { SomethingWrongErrorPage } from '@pages/ErrorPage'; | ||
|
||
export function UnknownErrorBoundary({ children }: PropsWithChildren) { | ||
const { reset } = useQueryErrorResetBoundary(); | ||
|
||
return ( | ||
<ErrorBoundary | ||
FallbackComponent={SomethingWrongErrorPage} | ||
onReset={reset} | ||
> | ||
{children} | ||
</ErrorBoundary> | ||
); | ||
} | ||
|
||
export default UnknownErrorBoundary; |
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,2 @@ | ||
export * from './APIErrorBoundary'; | ||
export * from './UnknownErrorBoundary'; |
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,8 @@ | ||
export function SomethingWrongErrorPage() { | ||
return ( | ||
<div> | ||
<h1>에러가 발생했습니다.</h1> | ||
<p>잠시 후 다시 시도해주세요.</p> | ||
</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 @@ | ||
export * from './SomethingWrongErrorPage'; |
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
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.
💬 라이브러리가 있구나!!