-
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
Migration ax fetch #149
Migration ax fetch #149
Conversation
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.
๊ณ ์ํ์ จ์ต๋๋ค!
- next ํ์ฅํ๋ ์์ฑ์ ์ฌ์ฉํ์ง ๋ชปํ๋ ๊ฑด ํฐ ์๋ฌ๋ค์,, ๋ฐ๊ฒฌํด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค
- ๊ฐ๋ฐ ์์ฐ์ฑ์ด ํฅ์๋๋ ๊ฒ์ ๋์ํ๋ฉฐ ๊ธฐ๋ฅ ์ถ๊ฐ๊ฐ ๋๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค
- ์ด ๋ถ๋ถ์ ์ด์ฐจํผ 404 ์๋ฌ๊ฐ ๋ ๊ฑฐ์ฌ์ ํฌ๊ฒ ๊ณ ๋ คํ์ง ๋ชปํ๋ค์ ์ด ๋ถ๋ถ๋ ํด๊ฒฐ์ด ํ์ํ ๊ฒ ๊ฐ์ต๋๋ค!
๊ทธ๋ฆฌ๊ตฌ ์คํ ๋ฆฌ๋ถ ํฌ๋ก๋งํฑ ์คํจ๋จ๋๊ฑฐ ํ์ธ ๋ถํ๋๋ ค์!
`${API_PATH.auth}/token`, | ||
{ refreshToken }, | ||
{ | ||
responseRejectedInterceptor: (error) => { |
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.
} catch (error:FetchAxError<ErrorData>) {
const status = error.statusCode;
switch (status) {
case HttpStatusCode.Unauthorized:
throw new UnauthorizedError({
message,
response,
});
}
}
FetchAX์์ error๋ฅผ throwํด์ค์ responseRejectedInterceptor๋ฅผ ์ฌ์ฉํ์ง ์์๋ ์์ฒ๋ผ catch๋ฌธ์์ ์ฒ๋ฆฌํ ์ ์์์ ๊ฒ ๊ฐ์๋ฐ ๋ฐ๋ก responseRejectedInterceptor๋ฅผ ์ฌ์ฉํ ์ด์ ๊ฐ ์๋์?!
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.
- ์ผ๋จ ํด๋น API๊ฐ Authorization ์์ฑ์ ๊ฐ์ด ๋ค์ด๊ฐ๋ฉด ์๋ฌ๋ฅผ ๋ฐ์์ํค๊ธฐ ๋๋ฌธ์, ์ด ๋ถ๋ถ๋ง ๊ธฐ์กด instance ๋์ fetchAx๋ฅผ ์ฌ์ฉํ์ต๋๋ค. ์๋ฌ ํธ๋ค๋ฌ๋ฅผ ์ถ๊ฐํ ์ด์ ๋ ๋ค๋ฅธ ์ฝ๋๋ค๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ์๋ฌ ์ธ์คํด์ค๋ฅผ ๋ฐ์ ์ผ๊ด์ ์ผ๋ก ์ฒ๋ฆฌํ๋ ๊ฒ์ด ๊ฐ๋ ์ฑ๊ณผ ์ ์ง๋ณด์ ์ธก๋ฉด์์ ๋ ์ ๋ฆฌํ๋ค๊ณ ํ๋จํ๊ธฐ ๋๋ฌธ์ ๋๋ค.
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.
์ํ ๋ต ๊ฐ์ฌํฉ๋๋ค!
ํน์ ์ด ๋ถ๋ถ์ ๋ํด์ ์กฐ๊ธ๋ง ๋ ์ค๋ช
ํด์ฃผ์ค ์ ์๋์!?
ํด๋น API๊ฐ Authorization ์์ฑ์ ๊ฐ์ด ๋ค์ด๊ฐ๋ฉด ์๋ฌ๋ฅผ ๋ฐ์
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.
๋ง๊ทธ๋๋ก ์ํ์ด๊ฐ ๋ง๋ ์ ์์ฒญ์๋ง ์ด์ํ๊ฒ Authorization์์ฑ์ ๊ฐ์ ๋ฃ์ด์ฃผ๋ฉด ์๋ฌ๊ฐ ๋ฐ์ํ๋๋ผ๊ตฌ์!
await instance.patch(`${API_PATH.user}/password`, body, { | ||
responseType: 'text', |
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.
responseType์ text๋ก ์ง์ ํ์ง ์์ผ๋ฉด ์๋ฌ๊ฐ ๋ฐ์ํ๋ค๋ ๋ง์ ๋ง์๊น์?
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.
- ๋ค ๋ง์ต๋๋ค!
app/utils/http/instance.ts
Outdated
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.
utils์ api ํด๋์ ์๋๊ฒ ๋ ์ ์ ํ์ง ์์๊น์?
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.
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.
์ข์ ์๊ฒฌ์ด๋ค์! ์์ ํ์ต๋๋ค
app/utils/http/instance.ts
Outdated
|
||
export const instance = fetchAx.create({ | ||
headers: { | ||
'Content-Type': 'application/json', |
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.
'Content-Type': 'application/json'
์ ๊ธฐ๋ณธ ๊ฐ์ด์ด์ ๋ฃ์ด์ฃผ์ง ์์๋ ๋์ง ์๋์!?
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.
- ๋ฆฌ๋ทฐ๊ฐ ๋๋ฝ๋์ด์ ๋ค์ ๋จ๊น๋๋ค.
- ์ ๋ ๋ํดํธ ๊ฐ์ธ ๊ฒฝ์ฐ์๋ ์ข ์ข ๋ช ์ํด์ฃผ๋ ๊ฒฝ์ฐ๊ฐ ์๋๋ฐ, ์ด๋ ๋ํดํธ ๊ฐ์ ๋ชจ๋ฅด๋ ์ฌ์ฉ์๋ ์ฝ๊ฒ ์ฝ๋๋ฅผ ์ดํดํ๊ณ ์ฌ์ฉํ ์ ์๊ฒ ํ๊ธฐ ์ํจ์ ๋๋ค. ํด๋น ํค๋ ๊ฐ๋ ๋ช ์ํด์ฃผ๋ฉด ์ฌ์ฉ์๊ฐ ๋ ์ฝ๊ฒ ์ดํดํ๊ณ ํ์ฉํ ์ ์์ ๊ฒ ๊ฐ์ ์ด๋ฅผ ํฌํจํ์ต๋๋ค.
@@ -40,6 +40,7 @@ | |||
"class-variance-authority": "^0.7.0", | |||
"clsx": "^2.1.0", | |||
"express": "^4.18.2", | |||
"fetch-ax": "^1.0.10", |
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.
์ค๋น ๊ฐ ์ด๋ฒ์ fetch-ax์ ์ฌ๋ฆฐ PR์ด ๋จธ์ง๋ ์ดํ์ fetch-ax ๋ฒ์ ์ ๋ฐ์ดํธ๊ฐ ํ์ํ ๊ฒ ๊ฐ์๋ฐ ์ด ๋ถ๋ถ์ ์ ๊ฐ ์์ ํ๋ฉด์ ์์ ํ๊ฒ ์ต๋๋ค~
์ฝ๋๋์ ๋ณํ๊ฐ ํฌ๋ค์.. ์ด์ ์๋ฌํธ๋ค๋ง ๊ธฐ๋ฅ์ด ํฐ ๋ชซ์ ํ ๊ฒ ๊ฐ์์ ์๊ณ ํ์
จ์ต๋๋ค. ๐ ์ ์ํด์ฃผ์ จ๋ ์๊ฒฌ๋ค์ ๋ํด์ ๊ฐ๋ฐ์ ์งํํ๋ ๊ฒ์ ์ฐฌ์ฑํ๋ ์ ์ฅ์ ๋๋ค. ๋น๋ฒํ๊ฒ ๋ฐ์ํ ์ผ์ด์ค๋ผ๊ณ ์๊ฐ์ด ๋ค์ด์. 2๋ฒ์ ๊ฒฝ์ฐ์๋ responseType์ ์ง์ ํ ๊ฒฝ์ฐ์๋ ์๋ฌ๊ฐ ๋ฐ์ํ ์ ์ด ์๋์? |
}, | ||
body: JSON.stringify(body), | ||
await instance.delete(`${API_PATH.user}/me`, { | ||
data: body, |
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.
axios ๋ฌธ๋ฒ์ ๋๋ fetch-ax๋ฅผ ์ฌ์ฉํ๋ ๋งํผ data
์์ฑ๋ช
์ ์ฌ์ฉํ๋ฉด ๊ฐ๋ฐ ์๋์ ๋ ๊ธด๋ฐํด์ง ์ ์์ ๊ฒ ๊ฐ์๋ฐ, ์์ฑ๋ช
๊ต์ฒด์ ๋ํด ํ์๋ถ๋ค์ ์ด๋ป๊ฒ ์๊ฐํ์๋์?
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.
์ ๋ ๊ณ ๋ คํด๋ดค๋๋ฐ, fetch-ax์ ์๋ต๊ฐ ์์ฑ ์ด๋ฆ์ด 'data'๋ผ์ ๊ฒน์น๋๋ผ๊ณ ์. ๊ทธ๋ฆฌ๊ณ ํ์ ๋ช ๋ ์ ํฌ๊ฐ 'Body'๋ก ์ค์ ํด๋์ 'body' ์์ฒด๋ ์ ๋ ๊ด์ฐฎ์ ๊ฒ ๊ฐ์ต๋๋ค.
๐storybook: https://65ccb85d5afe55a024495bc0-ftckjyrnga.chromatic.com/ |
๐storybook: https://65ccb85d5afe55a024495bc0-avcklafvre.chromatic.com/ |
ํฌ๋ก๋งํฑ ์์ ํ์ต๋๋ค! ์๋ฌ ์ฝ๋ ๊ด๋ จ์ผ๋ก ๊นจ์ง๋ ๊ฑฐ๋ผ ์์๋ฐฉํธ์ผ๋ก ์์ ํ ๊ฒ์ด๊ธด ํ๋ฐ, ์ข ๋ ์ ๋๋ก ๋ ์์ ์ ์๋ฌ ์ฝ๋ ์์ ๊ณผ ๋ณํํด์ผ ํ ๊ฒ ๊ฐ์ต๋๋ค. |
responseType์ ๋ง๊ฒ ์ง์ ํ ๊ฒฝ์ฐ ์๋ฌ๊ฐ ๋ฐ์ํ ์ ์ ์์ต๋๋ค |
๐ ์์ ๋ด์ฉ
๐ค ๊ณ ๋ฏผ ํ๋ ๋ถ๋ถ