-
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
chore: Axios 추가 #12
chore: Axios 추가 #12
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
const request = async ({ | ||
url, | ||
options = { | ||
method: 'GET', | ||
}, | ||
}) => { | ||
const response = await fetch(url, options); | ||
import axios from 'axios'; | ||
|
||
const instance = axios.create({ | ||
baseURL: '/', | ||
}); | ||
|
||
if (!response.ok) { | ||
const error = await response.json(); | ||
throw new Error(`서버의 응답이 올바르지 않습니다. (${response.status}): ${error.message}`); | ||
} | ||
instance.interceptors.request.use( | ||
(config) => { | ||
return config; | ||
}, | ||
(error) => { | ||
return Promise.reject(error); | ||
}, | ||
); | ||
|
||
return response.json(); | ||
}; | ||
instance.interceptors.response.use( | ||
(response) => { | ||
return response; | ||
}, | ||
(error) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: handlerErrorResponse 라는 함수에서 처리하시면 어떨까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. export const handleErrorResponse = (error) => {
if (error instanceof CustomError) {
console.log('CustomError: ', error.name, error.message);
return;
}
console.log('Error: ', error?.message);
}; 리뷰 주신 내용으로 handlerErrorResponse 함수 구현해보았습니다. |
||
const errorMessage = error.response ? `서버 응답이 올바르지 않습니다. ${error.response.status}: ${error.response.data.message}` : error.message; | ||
return Promise.reject(new Error(errorMessage)); | ||
}, | ||
); | ||
|
||
export default request; | ||
export default instance; |
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.
P3: 이런느낌으로 에러를 확장해서 쓰실 수 있어요! 추후에 센트리 설계하실때 입맛에 맞게 변경하실 수 있을거에요
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.
CustomError는 추가해보았는데, 아직 센트리를 반영하면서 어떤식으로 변경되는지는 감이 잘 오질 않네요.
센트리를 반영해보면서 더 고민해보도록 하겠습니다! 🙂