Skip to content

Commit 6c58323

Browse files
committed
gql 401 에러 처리 함수 추가
1 parent 1408399 commit 6c58323

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/fetcher/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export { authGuardedFetchers } from './auth-guarded-methods'
88
export {
99
captureHttpError,
1010
handle401Error,
11+
handleGql401Error,
1112
NEED_REFRESH_IDENTIFIER,
1213
ACCESS_TOKEN_EXPIRED_EXCEPTION,
1314
} from './response-handler'

packages/fetcher/src/response-handler.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { withScope, captureException } from '@sentry/nextjs'
2+
import { GraphQLError } from 'graphql'
23

34
import { HttpResponse } from './types'
45
import { NEED_LOGIN_IDENTIFIER } from './factories'
@@ -54,3 +55,18 @@ export async function handle401Error<SuccessBody, FailureBody>(
5455
}
5556
return NEED_LOGIN_IDENTIFIER
5657
}
58+
59+
interface ErrorResponse401 {
60+
status: number
61+
code: string
62+
name: string
63+
}
64+
65+
export function handleGql401Error(error: GraphQLError) {
66+
if (error.extensions?.originalError) {
67+
const originalError = error.extensions.originalError as ErrorResponse401
68+
if (originalError.status === 401) {
69+
return NEED_LOGIN_IDENTIFIER
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)