New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rety Middleware won't run after parser #1271
Comments
Update: I literally flipped the order of the two middlewares in the connection config block (while thinking "this can't possibly work") and now it works perfectly. Leaving this though because I have no idea what's going on and it still seems like a bug (or at least should be better-documented). |
Hi @mvastola, what you're experiencing is the expected behaviour! Hence you already did the right thing 🙌! By moving the I'm closing this now but feel free to follow-up if you have any further questions |
Thanks for the quick, kind, and thorough explaination. It's not that hard to understand, but it's a bit unintuitive here. I wonder if there's an effective way to make it less so. DocsI had actually seen the documentation you linked, and it made me think I knew what I needed to do. (I saw the picture, and the stuff about "innermost" middleware, but I didn't really process that it meant reversing the order.) The image shown is informative with regard to the internals of middleware, but it might be helpful to compliment it with a visual indication of how the order in the config block affects the run order. ConfigurationBeyond that, there are a bunch of details of this implementation that make this unintuitive:
Anyway I'm happy to try to think up some ideas if you're open to tweaking the API for this issue. Otherwise at least I get this now. I'm only saying this because I can easily see other users suffering the same confusion here. |
Thanks @mvastola, this is invaluable feedback 🙏! When it comes to documentation, I agree we're a long way off, so any contribution to improve that is very much welcome (there's actually a very recent discussion thread about that!). The points on configuration are also very valid, let me just say that the |
Basic Info
Issue description
NB: Please let me know if this belongs in
faraday_middleware
instead. As it involves two middlewares, I didn't know where to put it.When creating a connection, I expect (as is documented) the middleware will run in the order it is declared. However, when a request fails and I load the
:json
parsing middleware followed by the:retry
middleware,env.body
is unparsed in the scope of the:retry
middleware's:retry_if
block:I need to run the
:retry_if
block on theJSON
-decoded message because the JSON document can be very large if the request is successful, and the alternative is to parse it a second time in theretry_if
, which seems totally unnecessary.Steps to reproduce
Note: If I print
f.instance_variable_get :@handlers
, inside the block, I see the middleware in the order I declared it.When a request fails, and I evaluate these expressions in the
:retry
middleware's:retry_if
block, I get the following output:Basically, the parsing middleware just refuses to run first.
The JSON is well-formed and the response's
Content-Type
header is correctly set, so I'm stumped.My only guess is it's something to do with
#response
middleware always runs before#request
middleware, but in this caseretry
being#request
middleware is something of a misnomer because it implicitly needs to be evaluated after the response is returned.The text was updated successfully, but these errors were encountered: