What is the best way to deal with a fetch error in react redux?

前端 未结 6 1961
名媛妹妹
名媛妹妹 2020-12-04 04:41

I have one reducer for Clients, one other for AppToolbar and some others...

Now lets say that I created a fetch action to delete client, and if it fails I have code

6条回答
  •  鱼传尺愫
    2020-12-04 05:15

    You can use axios HTTP client. It already has implemented Interceptors feature. You can intercept requests or responses before they are handled by then or catch.

    https://github.com/mzabriskie/axios#interceptors

    // Add a request interceptor
    axios.interceptors.request.use(function (config) {
        // Do something before request is sent
        return config;
      }, function (error) {
        // Do something with request error
        return Promise.reject(error);
      });
    
    // Add a response interceptor
    axios.interceptors.response.use(function (response) {
        // Do something with response data
        return response;
      }, function (error) {
        // Do something with response error
        return Promise.reject(error);
      });

提交回复
热议问题