Kimyeongkyung
Axios interceptors 본문
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를 가공 및 수정
- 에러 핸들링
- 로깅
- 로딩 상태 관리
- 상태 관리
- 기타
'important' 카테고리의 다른 글
지정 접미사로 끝나는지 판단하는 메서드 endsWith() (0) | 2023.11.11 |
---|---|
replace() vs replaceAll() (0) | 2023.08.23 |
단언 연산자 (!.) (0) | 2023.04.10 |
fatal: too many arguments for a rename operation 에러 (0) | 2023.04.05 |
react textarea 줄바꿈(개행) 이슈 처리하기 위한 과정 (0) | 2022.12.08 |