Skip to content

Commit 5d1de93

Browse files
committed
review에 gql 401 에러 적용
1 parent 0a80bbc commit 5d1de93

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { handleGql401Error } from '@titicaca/fetcher'
2+
import { useLoginCtaModal } from '@titicaca/modals'
3+
import { ClientError } from 'graphql-request'
4+
5+
export function useShowLoginCtaModalOnAuthError() {
6+
const { show: showLoginCta } = useLoginCtaModal()
7+
8+
return (error: unknown) => {
9+
if (error instanceof ClientError) {
10+
const isAuthError = error.response.errors?.some((err) =>
11+
handleGql401Error(err),
12+
)
13+
if (isAuthError) {
14+
showLoginCta()
15+
}
16+
}
17+
}
18+
}

packages/review/src/services/use-reviews.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import {
2323
GetReviewsCountQuery,
2424
} from '../data/graphql'
2525

26+
import { useShowLoginCtaModalOnAuthError } from './hooks'
27+
2628
export function useReviewCount(
2729
params: GetReviewsCountQueryVariables,
2830
initialValue?: number,
@@ -63,11 +65,15 @@ export function useMyReview(params: GetMyReviewQueryVariables) {
6365
export function useLikeReviewMutation() {
6466
const { notifyReviewLiked } = useTripleClientActions()
6567
const queryClient = useQueryClient()
68+
const showLoginCtaModalOnAuthError = useShowLoginCtaModalOnAuthError()
6669

6770
return useMutation(
6871
(variables: LikeReviewMutationVariables & { resourceId: string }) =>
6972
reviewClient(() => client.LikeReview({ reviewId: variables.reviewId })),
7073
{
74+
onError: (error) => {
75+
showLoginCtaModalOnAuthError(error)
76+
},
7177
onSuccess: (data, variables) => {
7278
notifyReviewLiked?.(variables.resourceId, variables.reviewId)
7379

@@ -168,11 +174,15 @@ export function useLikeReviewMutation() {
168174
export function useUnlikeReviewMutation() {
169175
const { notifyReviewUnliked } = useTripleClientActions()
170176
const queryClient = useQueryClient()
177+
const showLoginCtaModalOnAuthError = useShowLoginCtaModalOnAuthError()
171178

172179
return useMutation(
173180
(variables: UnlikeReviewMutationVariables & { resourceId: string }) =>
174181
reviewClient(() => client.UnlikeReview({ reviewId: variables.reviewId })),
175182
{
183+
onError: (error) => {
184+
showLoginCtaModalOnAuthError(error)
185+
},
176186
onSuccess: (data, variables) => {
177187
notifyReviewUnliked?.(variables.resourceId, variables.reviewId)
178188

@@ -272,6 +282,7 @@ export function useUnlikeReviewMutation() {
272282
export function useDeleteReviewMutation() {
273283
const { notifyReviewDeleted } = useTripleClientActions()
274284
const queryClient = useQueryClient()
285+
const showLoginCtaModalOnAuthError = useShowLoginCtaModalOnAuthError()
275286

276287
return useMutation(
277288
async (
@@ -281,6 +292,9 @@ export function useDeleteReviewMutation() {
281292
},
282293
) => reviewClient(() => client.DeleteReview(variables)),
283294
{
295+
onError: (error) => {
296+
showLoginCtaModalOnAuthError(error)
297+
},
284298
onSuccess: (data, variables) => {
285299
notifyReviewDeleted?.(
286300
variables.resourceId,

0 commit comments

Comments
 (0)