svrcekmichal / redux-axios-middleware

Redux middleware for fetching data with axios HTTP client
MIT License
920 stars 96 forks source link

intercepting: getSourceAction in response is returning undefined #64

Closed mgenov closed 7 years ago

mgenov commented 7 years ago

Is this intended to work only for the request ? On my side calling getSourceAction by passing the response is returning undefined. Here is a sample snippet:

response: [
      {
        success: ({ dispatch, getSourceAction }, response) => {
          console.log(getSourceAction(response))
          return Promise.resolve(response)
        },
        error: ({ dispatch, getSourceAction }, error) => {
          console.log(getSourceAction(error))
          return Promise.reject(error)
        }
      }
    ]

What I'm trying to accomplish is refreshing of a token when it expires and server returns that request is not authorized.

Here is an example how this could be accomplished using axios interceptors: https://plnkr.co/edit/0ZLpc8jgKI18w4c0f905?p=preview

mgenov commented 7 years ago

I'm open to contribute this change if team accepts this feature.

mgenov commented 7 years ago

The config is available in response.config and action is able to be retrieved with:

console.log('sourceAction: ', getSourceAction(error.config));

Everything looks fine, so I'm closing the issue.