서버로 요청을 보내는것과 서버에서 받은 응답을 화면(컴포넌트)단에서 처리하기전에

추가로직을 넣을수 있는 API

 

인터셉터를통해 token을 실어보낼 수 있다.

 

// Add a request interceptor
axios.interceptors.request.use(function (config) {
    // 요청보내기 전 코드
    return config;
  }, function (error) {
    // 요청에러 처리
    return Promise.reject(error);
  });

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // 응답을 받기 전에 처리
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response;
  }, function (error) {
    // 응답에러 전처리
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  });

 

반응형

+ Recent posts