Closed svrcekmichal closed 7 years ago
It looks like we are just waiting for confirmation from the OP of #34 to confirm that it solved the issue.
@nmaves I don't believe it will work. I was quite naive with my little testing of this PR. Solution proposed by @tlenclos looks better from my point of view. The question is, aren't we doing too much to support axios interceptors? bending whole axios and redux to play nicely while we can implement interceptors ourself, it's few lines of code and have nicer API overall?
I am not against that @svrcekmichal. Can you give me an example of how we would handle it on our side?
Well, my idea was to create nicer API for whole middleware, for example would be created with closure createAxiosClient(name, axiosConfig)
. Function will return closure with multiple functions to setup middleware options and also three new functions getClient
, addRequestInterceptor
and addResponseInterceptor
.
getClient
will handle logic about creating axios client instance when first time needed and two other functions describe what they do. Implementation of interceptors is only chaining of promises before and after the request is made
We definitly need to handle a stack to link the action that started the request with the response. I got a new bug in my app when I start two different requests in parallels, the second is linked with the first action 😞 .
I believe we can try and publish @benarmston solution to see if it will work for now, before we remake it completly. If anyone can make PR to this branch it would be great. If not I will try to handle as soon as I can.
Yes, @svrcekmichal do you want me to work on this ?
@tlenclos would be great 👍
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
The getSourceAction receives the config object, which is nested under response at response.config
response: [
{
success: ({ dispatch, getSourceAction }, response) => {
console.log(getSourceAction(response.config))
return Promise.resolve(response)
},
error: ({ dispatch, getSourceAction }, error) => {
console.log(getSourceAction(error.config))
return Promise.reject(error)
}
}
]
Hello there, something is blocking this PR ?