title: Catch errors using redux-thunk
body: <p>I'm using redux-thunk to make API calls in my React app. </p>
  
  <p>Every 30 minutes, the user's bearer token expires, and instead of forcing them to login again I call <code>auth/refresh</code>. This is a pain, because I need to check for <code>401 error</code> every time a call is made. Is there a way using redux/redux-thunk to check for this error in one place, rather than in every call?</p>
  
  <p>I have the added problem that if multiple calls happen, the same refresh is called every time, so I end up refreshing the bearer token multiple times!</p>
  
  <p>My action for refreshing the auth token:</p>
  
  <pre><code>export const refreshAuth = () =&gt; {
    return (dispatch, getState) =&gt; {
      return axios.post(API.path + 'auth/refresh/?' + API.beaconAPI_client, { 'refreshToken': getState().login.refreshToken })
      .then(response =&gt; {
          dispatch({
              type: DO_LOGIN_REFRESH,
              userDetails: response.data
          })
      })
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Using Axios, if an error occurs I do this:</p>
  
  <pre><code>.catch(error =&gt; {
    if(error.response.status === 401){
      this.props.refreshAuth()
      .then(response =&gt; {
          /* In the response, make the request again after auth is refreshed */
      })
    }
  })
  </code></pre>