使用 axios 拦截器处理补丁请求

时间:2021-07-06 12:21:52

标签: node.js axios

我正在努力理解 axios 拦截器是如何使用的。在我发现的每个示例中都使用了这样的代码

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);
  });

但是我如何使用它来拦截我的补丁请求的响应?

       axios.patch(addr, data, {
           headers: this.headers,
          httpsAgent: this.agent,
     })
           .then(res => {
                  resolve(true)
                })
                .catch(error => {
                    resolve(false);
                })

0 个答案:

没有答案