What are people’s preferred method for implementing retries when an XHR from re-frame-http-fx times out?
One can naively create an :on-failure event that checks (= :timeout (:failure response)) , but I dont like this since it involves manually reconstructing the event, and it seems to abstract this into a “composable” or “generic” event handler.
I rarely use interceptors, so I don’t have a good intuition for them, but they seem to solve the issue of reconstructing the original http-fx event that failed. So I want to consider trying them out. Has anyone here tried using interceptors for this? and if so, do you have a simple example?
> manually reconstructing the event Why? You already have the whole event vector there, just pass it along, maybe with a retry counter.
When the :on-failure event is fired, I only get the event vector of the failure handler, not the event that makes the AJAX call
e.g. suppose I (rf/dispatch [:api/get-things {:id 123 :on-success [:handle-success] :on-failure [:handle-failure]])
You have the original event vector where you create the XHR effect.
You can pass that vector to the :on-failure event vector. Event in event.
ah, now I understood your point
thanks!
you’re absolutely right… the event vector in my above example is already in the :api/get-things handler…
it’s tough seeing this since I almost always use trim-v on my event handlers and forget that this has utility at times 🙂
Heh, yeah.
You can get the original event vector as :original-event coeffect if trim-v is used.