Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Kimyeongkyung

Axios interceptors 본문

important

Axios interceptors

yeongk0825 2023. 4. 12. 18:00

Axios interceptor

 

request와 response가 then과 catch에 의해 처리되기 전에 전역적으로 가로채게 허용해주는 axios library

  • header 추가, 인증 관리, 로깅, 에러 처리 등의 작업을 할때 매우 유용
  • interceptor들은 http request나 response 객체와 함께 호출되는 함수이다.
  • 단일 interceptorsms 객체가 전달되기 전에 객체를 변화하도록 선택할 수도 있고, 이어지는 process에 체인(훅)을 걸어 다음에 동작할 함수를 선택할 수도 있다.

정리)

axios의 return이 Promise 타입인 점을 이용해 http request, response가 then이나 catch가 처리되기 이전에 부가적인 작업을 할 수 있도록 도와주는 library

 

Request interceptors

  • request config 바꾸기
  • header 추가
  • 인증 관련 작업(ex.token 추가)
  • 로깅
  • 로딩 상태 관리

 

Response interceptors

  • response의 data를 가공 및 수정
  • 에러 핸들링
  • 로깅
  • 로딩 상태 관리
  • 상태 관리
  • 기타

참고자료 
https://leeseong010.tistory.com/133