title: Is there a way to set global axios config for error response codes
body: <p>I'm using <code>axios</code> in my react/redux application and when I get errors like 401, 404, etc I currently have to deal with them for each action function when I make the calls to axios. I have a axios_config.js where I've wrapped the axios calls with some common idioms. For example:</p>
  
  <pre><code>// need to move this to app config
  const BASE_URL = 'http://localhost:8080/api/';
  
  function config() {
    return {
      headers: {'X-Token-Auth': localStorage.getItem('token')}
    }
  }
  
  export function fetchData(url) {
    return axios.get(`${BASE_URL}${url}`, config());
  };
  </code></pre>
  
  <p>Where I'm struggling are the common errors like 401, 404, etc. Currently, I'm doing this:</p>
  
  <pre><code>export function fetchBrands() {
    return function(dispatch) {
      dispatch({type:FETCHING_BRANDS});
  
      fetchData('brands')
        .then(response =&gt; {
          dispatch({
            type: FETCH_BRANDS_SUCCESS,
            payload: response
          });
        })
        .catch(err =&gt; {
          // deal with errors
        });
    }
  }
  </code></pre>
  
  <p>But in the <code>catch</code> block, I don't want to have to deal with 401, 404 etc every single time. So I need to be able to deal with those on a more global scale but still have the ability to handle specific errors to the request like server side validation errors for example.</p>