then 또는 catch로 처리되기 전에 요청과 응답을 가로챌 수 있다.
// 요청 인터셉터 추가
// 커스텀 인스턴스에서도 인터셉터 추가 가능
axios.interceptors.response.use(function (response) {
// 응답 데이터가 있는 작업 수행
return response
}, function (error) {
// 응답 오류가 있는 작업 수행
return Promise.reject(error);
});
나중에 필요할 때 인터셉터를 제거할 수 있다.
const myInterceptor = axios.interceptors.requeset.use(function () {/*>..*/});
axios.interceptors.request.reject(myInterceptor);
'Axios 공식 홈페이지 따라하기' 카테고리의 다른 글
Axios 공식 홈페이지 따라하기 (9) - URL-인코딩 바디 (0) | 2025.02.05 |
---|---|
Axios 공식 홈페이지 따라하기 (8) - 에러 핸들링 (0) | 2025.02.05 |
Axios 공식 홈페이지 따라하기 (6) - Config 기본값 (0) | 2025.02.05 |
Axios 공식 홈페이지 따라하기 (5) - 응답 스키마 (0) | 2025.02.05 |
Axios 공식 홈페이지 따라하기 (4) - 요청 Config (0) | 2025.02.05 |