You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you look at the openapi-fetchAPI docs, it says you can give middleware array as "fetch options" to the request methods.
The following options apply to all request methods (.GET(), .POST(), etc.)
But in source code of v0.13.0, we can see middlewares used are only the ones from the root createClient scope.
Took a while to realise this when debugging why my middleware didn't seem to do anything...
Proposal
I have a use case, where in certain frontend scenarios I wanted to attach "show generic error modal on error response" middleware for group of requests.
I don't want that middleware to be global (createClient level).
Because of mutable client state, I think I can't call use(myMw) and instantly eject(myMw) after the request has been handled, as nothing can't guarantee that during the async fetch request, no other request would be fired (and thus accidentally use this "temp" middleware) from event-loop while waiting for the async work to be finished.
I could handle this case request by request by checking the returned error and then show modal, but that feels not-so-elegant compared to middleware.
I could create another client which would vary only by this one added mw, but it feels too heavy weight.
On the other hand, I understand that it is not actually trivial to define "per request middleware"...
Should they replace the "global" middlewares? Or should they be pushed to the array after the global middleware?
Order of execution is not instantly clear without explicit documentation. I can imagine users might have different assumptions on what the middlewares' execution order would be if both global and per-request middleware are defined.
Axios didn't seem to have support for such either.
Summary
I guess docs need fixing by removing part that suggests middleware can be set on per request basis. Or have I understood something totally wrong? Please enlighten me 😀
Ideas/thoughts about "per request middleware"? Does it make any sense? I was initially happy to find from docs that I could solve my issue directly as a request option. Is there some obvious (semi-elegant) way to handle my use case that I just can't see right now?
Thanks for the lib(s), eagerly waiting for next progression steps 💪 👏
ps. I am not native in english, so might well be I am misunderstanding the docs.
pps. Best medium to ask stupid questions regarding the lib and especially type inference challenges? Do you guys have Discord or such? I also understand if such medium is not feasible because of the noise/nuisance it might cause. Just wanted to ask as I've had several situations where rubberducking with someone more experienced with the lib would've been both beneficial and educational!
Description
If you look at the
openapi-fetch
API docs, it says you can givemiddleware
array as "fetch options" to the request methods.But in source code of v0.13.0, we can see middlewares used are only the ones from the root
createClient
scope.Took a while to realise this when debugging why my middleware didn't seem to do anything...
Proposal
I have a use case, where in certain frontend scenarios I wanted to attach "show generic error modal on error response" middleware for group of requests.
I don't want that middleware to be global (
createClient
level).Because of mutable client state, I think I can't call
use(myMw)
and instantlyeject(myMw)
after the request has been handled, as nothing can't guarantee that during the async fetch request, no other request would be fired (and thus accidentally use this "temp" middleware) from event-loop while waiting for the async work to be finished.I could handle this case request by request by checking the returned
error
and then show modal, but that feels not-so-elegant compared to middleware.I could create another client which would vary only by this one added mw, but it feels too heavy weight.
On the other hand, I understand that it is not actually trivial to define "per request middleware"...
Should they replace the "global" middlewares? Or should they be pushed to the array after the global middleware?
Order of execution is not instantly clear without explicit documentation. I can imagine users might have different assumptions on what the middlewares' execution order would be if both global and per-request middleware are defined.
Axios didn't seem to have support for such either.
Summary
middleware
can be set on per request basis. Or have I understood something totally wrong? Please enlighten me 😀Thanks for the lib(s), eagerly waiting for next progression steps 💪 👏
ps. I am not native in english, so might well be I am misunderstanding the docs.
pps. Best medium to ask stupid questions regarding the lib and especially type inference challenges? Do you guys have Discord or such? I also understand if such medium is not feasible because of the noise/nuisance it might cause. Just wanted to ask as I've had several situations where rubberducking with someone more experienced with the lib would've been both beneficial and educational!
Checklist
The text was updated successfully, but these errors were encountered: