How can I get the status code from an http error in Axios?

前端 未结 10 1945
南旧
南旧 2020-11-28 02:27

This may seem stupid, but I\'m trying to get the error data when a request fails in Axios.

axios.get(\'foo.com\')
    .then((response) => {})
    .catch((         


        
10条回答
  •  渐次进展
    2020-11-28 02:51

    I am using this interceptors to get the error response.

    const HttpClient = axios.create({
      baseURL: env.baseUrl,
    });
    
    HttpClient.interceptors.response.use((response) => {
      return response;
    }, (error) => {
      return Promise.resolve({ error });
    });
    

提交回复
热议问题