redux-api icon indicating copy to clipboard operation
redux-api copied to clipboard

Add action to postfetch function params

Open jakeaaron opened this issue 7 years ago • 8 comments

We already get request options in the function, but I am wanting to retry an action if the fetch fails. If we had the action in the postfetch I could just dispatch the action again.

Is there a different way to retry an action if it fails?

jakeaaron avatar Aug 10 '17 19:08 jakeaaron

Hi @jakeaaron Very interesting question. I think that at this moment postfetch is only way.

lexich avatar Aug 10 '17 20:08 lexich

But it's good feature request

lexich avatar Aug 10 '17 20:08 lexich

Thanks for the response @lexich. I don't think it's possible with postfetch at this moment, because we're not getting the action type in the function. Is this correct?

jakeaaron avatar Aug 10 '17 20:08 jakeaaron

There is another way. You can use https://github.com/lexich/redux-api/blob/master/docs/DOCS.md#responsehandler and implement here retry logic

lexich avatar Aug 10 '17 20:08 lexich

Oh! I didn't realize... you can dispatch an action in responseHandler?

jakeaaron avatar Aug 10 '17 20:08 jakeaaron

Yes responsehandler is bad idea in this case. But you can write custom adapter and you'll have access to request properties.

lexich avatar Aug 10 '17 20:08 lexich

2 questions:

  1. Does post fetch not get called on a fetch failure?
  2. Do you think it would be sufficient to just return the action type since we're already returning the request?

jakeaaron avatar Aug 11 '17 14:08 jakeaaron

  1. Yes, postfetch called only on success.
  2. I didn't understand, what's you mean, maybe example?

lexich avatar Aug 11 '17 15:08 lexich