-
Notifications
You must be signed in to change notification settings - Fork 0
[Qnrr 522] mutation error handling #149
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
Open
aken-you
wants to merge
6
commits into
develop
Choose a base branch
from
QNRR-522-error-handling
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1fbef99
feat: 전역 에러 페이지 생성
aken-you d2d4872
feat: 스터디 신청 mutation onError 설정
aken-you 4f59709
feat: 회원가입 mutation onError 설정
aken-you 81851a8
feat: 회원 프로필 업데이트 mutation onError 설정
aken-you bb7a15f
feat: 스터디 후기 등록 mutation onError 설정
aken-you 44efe43
refactor: 전역 에러 컴포넌트 새로고침 핸들러 수정
aken-you 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| 'use client'; | ||
|
|
||
| import { useRouter } from 'next/navigation'; | ||
| import { startTransition } from 'react'; | ||
| import Button from '@/shared/ui/button'; | ||
|
|
||
| export default function ErrorBoundary({ | ||
| error, | ||
| reset, | ||
| }: { | ||
| error: Error; | ||
| reset: () => void; | ||
| }) { | ||
| const router = useRouter(); | ||
|
|
||
| return ( | ||
| <div className="flex h-[calc(100vh-45px)] flex-col items-center justify-center gap-400"> | ||
| <div className="flex flex-col items-center justify-center gap-150"> | ||
| <h1 className="font-designer-28b"> | ||
| 서비스 이용에 불편드려 죄송합니다. | ||
| </h1> | ||
| <div className="flex flex-col items-center gap-50"> | ||
| <span className="font-designer-16m text-text-subtle"> | ||
| 에러가 발생하여 페이지를 표시할 수 없습니다. | ||
| </span> | ||
| <span className="font-designer-16m text-text-subtle"> | ||
| 잠시 뒤에 다시 시도해주세요. | ||
| </span> | ||
| </div> | ||
| </div> | ||
| <Button | ||
| size="large" | ||
| onClick={() => { | ||
| startTransition(() => { | ||
| router.refresh(); // 서버 컴포넌트들을 다시 렌더링 | ||
| reset(); // 에러 상태 초기화 | ||
| }); | ||
| }} | ||
| > | ||
| 새로고침 | ||
| </Button> | ||
| </div> | ||
| ); | ||
| } | ||
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'; | |||||
| import { useRouter } from 'next/navigation'; | ||||||
| import { logout, signUp, uploadProfileImage } from '@/features/auth/api/auth'; | ||||||
| import { hashValue } from '@/shared/lib/hash'; | ||||||
| import { isApiError } from '@/shared/tanstack-query/api-error'; | ||||||
| import { deleteCookie, getCookie } from '@/shared/tanstack-query/cookie'; | ||||||
| import { SignUpResponse } from './types'; | ||||||
|
|
||||||
|
|
@@ -16,6 +17,13 @@ export const useSignUpMutation = () => { | |||||
| { name: string; imageExtension: string } | ||||||
| >({ | ||||||
| mutationFn: (data: any) => signUp(data), | ||||||
|
||||||
| mutationFn: (data: any) => signUp(data), | |
| mutationFn: (data: { name: string; imageExtension: string }) => signUp(data), |
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
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.
router.refresh 메서드가 비동기적으로 동작하여, 서버 컴포넌트를 다시 렌더링하지 못하는 문제가 있었어요.
refresh 메서드가 promise를 반환하지 않기 때문에 async await을 사용할 수 없었어요.
그래서 startTransition을 써서 refresh, reset 작업의 우선순위를 뒤로 늦췄어요. refresh 실행한 다음에 reset이 일어난다 까지는 찾지 못했으나, React 내부적으로 refresh가 reset 작업보다 먼저 처리하는 것 같아요.
참고 블로그
startTransition의 콜백 안에 두 메서드 다 넣는 경우도 있고, reset 만 넣는 경우도 있었어요.