-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from YAPP-Github/feature/FE-088
feature/FE-088 : 로그인 유지 로직 추가
- Loading branch information
Showing
2 changed files
with
15 additions
and
10 deletions.
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
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 |
---|---|---|
@@ -1,16 +1,18 @@ | ||
import { AfterResponseHook } from 'ky'; | ||
import ky, { AfterResponseHook } from 'ky'; | ||
import { ResponseData } from '@/types/data'; | ||
|
||
import { userAPI } from '@/api/user/api'; | ||
/** response 에서 필요한 데이터 추출 및 에러 전처리 */ | ||
const processResponse: AfterResponseHook = async (request, options, response) => { | ||
if (response.status === 204) { | ||
return new Response(undefined, { status: 204 }); | ||
} | ||
|
||
const data: ResponseData = await response?.json(); | ||
return new Response(JSON.stringify(data?.result ?? data?.message), { | ||
status: response.status, | ||
}); | ||
if (response.status === 204) { | ||
return new Response(undefined, { status: 204 }); | ||
} else if (response.status === 498) { | ||
await userAPI.postRefresh(); | ||
return ky(request); | ||
} | ||
const data: ResponseData = await response?.json(); | ||
return new Response(JSON.stringify(data?.result ?? data?.message), { | ||
status: response.status, | ||
}); | ||
}; | ||
|
||
export { processResponse }; |