Conditional streaming based on status code #1500
Replies: 2 comments 2 replies
-
To elaborate a bit on my scenario, this is basically what I have right now:
Then in my
What I would prefer is:
If a callback were supported by |
Beta Was this translation helpful? Give feedback.
-
Hello @md5, thank you for opening this discussion and for all the details provided 🙏! Streaming is a fairly recent feature, so this kind of feedback is really appreciated. I'm glad the current implementation is flexible enough for you to still be able to achieve what you want, but I'm always happy to explore how we can make Faraday smarter and more helpful. I'm currently away from my laptop and won't be back until later in the week, so apologies if I can't look further into this right now, but I'll make a note to do so once I'm back 👍. To provide some quick and short feedback to your points:
|
Beta Was this translation helpful? Give feedback.
-
I have a scenario where I am streaming large files from AWS S3 with
on_data
and we occasionally run into S3 errors. When this happens, S3 returns an XML response body that gives more detail on the nature of the error, beyond what the HTTP status code provides on its own.I was hoping that I could have code in
on_data
that collects chunks intoenv[:response_body]
for error status codes while still streaming chunks to the appropriate sink in the case of successful responses, but it looks like (most of) the adapters explicitly set the response body to''
ornil
after all chunks have been sent toon_data
.I've been able to work around this by putting the error response body into
env[:error_body]
instead, but this complicates the middleware that I want to parse the error response body because it can't just look at:response_body
and needs to look at this other non-standard key as well.An additional goal I have is to either customize the error class or error message raised by the
:raise_error
middleware to include the<Code>
and<Message>
elements from the S3 XML response. I've been able to work around this by rescuing and re-raising the error raised by:raise_error
after modifying the message to include the additional data, but it seems very hacky and brittle.I'd love to get any thoughts that others may have on this use case and see if there is something I've missed.
Beta Was this translation helpful? Give feedback.
All reactions