title: Axios Interceptors retry original request and access original promise
body: <p>I have an interceptor in place to catch 401 errors if the access token expires. If it expires it tries the refresh token to get a new access token. If any other calls are made during this time they are queued until the access token is validated.</p>
  
  <p>This is all working very well. However when processing the queue using Axios(originalRequest) the originally attached promises are not being called. See below for an example.</p>
  
  <p>Working interceptor code:</p>
  
  <pre><code>Axios.interceptors.response.use(
    response =&gt; response,
    (error) =&gt; {
      const status = error.response ? error.response.status : null
      const originalRequest = error.config
  
      if (status === 401) {
        if (!store.state.auth.isRefreshing) {
          store.dispatch('auth/refresh')
        }
  
        const retryOrigReq = store.dispatch('auth/subscribe', token =&gt; {
          originalRequest.headers['Authorization'] = 'Bearer ' + token
          Axios(originalRequest)
        })
  
        return retryOrigReq
      } else {
        return Promise.reject(error)
      }
    }
  )
  </code></pre>
  
  <p>Refresh Method (Used the refresh token to get a new access token)</p>
  
  <pre><code>refresh ({ commit }) {
    commit(types.REFRESHING, true)
    Vue.$http.post('/login/refresh', {
      refresh_token: store.getters['auth/refreshToken']
    }).then(response =&gt; {
      if (response.status === 401) {
        store.dispatch('auth/reset')
        store.dispatch('app/error', 'You have been logged out.')
      } else {
        commit(types.AUTH, {
          access_token: response.data.access_token,
          refresh_token: response.data.refresh_token
        })
        store.dispatch('auth/refreshed', response.data.access_token)
      }
    }).catch(() =&gt; {
      store.dispatch('auth/reset')
      store.dispatch('app/error', 'You have been logged out.')
    })
  },
  </code></pre>
  
  <p>Subscribe method in auth/actions module:</p>
  
  <pre><code>subscribe ({ commit }, request) {
    commit(types.SUBSCRIBEREFRESH, request)
    return request
  },
  </code></pre>
  
  <p>As well as the Mutation:</p>
  
  <pre><code>[SUBSCRIBEREFRESH] (state, request) {
    state.refreshSubscribers.push(request)
  },
  </code></pre>
  
  <p>Here is a sample action:</p>
  
  <pre><code>Vue.$http.get('/users/' + rootState.auth.user.id + '/tasks').then(response =&gt; {
    if (response &amp;&amp; response.data) {
      commit(types.NOTIFICATIONS, response.data || [])
    }
  })
  </code></pre>
  
  <p>If this request was added to the queue I because the refresh token had to access a new token I would like to attach the original then():</p>
  
  <pre><code>  const retryOrigReq = store.dispatch('auth/subscribe', token =&gt; {
      originalRequest.headers['Authorization'] = 'Bearer ' + token
      // I would like to attache the original .then() as it contained critical functions to be called after the request was completed. Usually mutating a store etc...
      Axios(originalRequest).then(//if then present attache here)
    })
  </code></pre>
  
  <p>Once the access token has been refreshed the queue of requests is processed:</p>
  
  <pre><code>refreshed ({ commit }, token) {
    commit(types.REFRESHING, false)
    store.state.auth.refreshSubscribers.map(cb =&gt; cb(token))
    commit(types.CLEARSUBSCRIBERS)
  },
  </code></pre>