-
Notifications
You must be signed in to change notification settings - Fork 0
[ICC-54] 에러 메시지 + axios #9
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
Conversation
| method: "POST", | ||
| body: formData, | ||
| const res = await axiosInstance.post(`/s3/upload`, formData, { | ||
| isMultipart: true, |
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로 두었습니다 multipart라면
{
isMultipart: true,
}
로 옵션을 주면 됩니다
| import axios from "axios"; | ||
| const apiBaseURL = import.meta.env.VITE_BASE_URL; | ||
|
|
||
| const axiosInstance = axios.create({ |
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.
- base-url: axiosInstance 생성 시점에만 등록해주면 됩니다
- method: 함수로 호출하면 됩니다: axiosInstance.get, axiosInstance.post등...
- Content-Type: 기본적으로 application/json로 두었습니다 multipart라면
{
isMultipart: true,
}
로 옵션을 주면 됩니다
|
|
||
| axiosInstance.interceptors.response.use( | ||
| (response) => response, | ||
| (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.
- 에러메시지 알림창을 띄워주는 코드를 한 곳에만 작성하면됩니다
- 그후 Promise.reject를 호출하여 상위 스코프에 throw합니다
| throw new Error(errText || "해설 불러오기 실패"); | ||
| } | ||
| const data = await res.json(); | ||
| const res = await axiosInstance.get(`/explanation/${problemSetId}`); |
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.
method: 함수로 호출하면 됩니다: axiosInstance.get, axiosInstance.post등...
axiosInstance: 코드에도 설명 적어놓았습니다
한 곳에서 http요청을 관리합니다
로 옵션을 주면 됩니다
한 곳에서 http응답을 관리합니다
toast
alert창 대신 예쁜 모달을 띄워주는 라이브러리입니다


체크리스트
npm install