-
-
Notifications
You must be signed in to change notification settings - Fork 387
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
Make error body available in FlurlHttpException.Message (opt-in?) for generic logging #765
Comments
I'm not sure I follow. Have you looked at using the |
I definitely used the wrong language as I've looked at it. From my understanding, it's just a global error handler for the same/similar code I snippeted above. I suggest adding a new Exception type that already has the response body assigned to it. Something like I understand there is computational performance involved in reading the response, so I get why I think newcomers to the library would benefit from this enhancement as well. Many times, I've seen code where the It's not something critical by any means as people have been doing it the long-form way, but I'd like to make this the default error handler in a simple wrapping API method via Flurl if possible.
I guess I'm just getting at the fact that I (maybe incorrectly) assume that people would generally always want the response's body to be included in the exception if Flurl had thrown one at all. Doing the extra work to go and get it and handle the exception better than the library feels like a feature miss? |
Not necessarily. Sometimes the HTTP status code is good enough. Flurl basically gives you 3 options:
Keep in mind that options 1 & 2 are both one-liners in your catch block. I'm not seeing a real benefit of a new exception type, especially if you need to opt in with something like your |
No problem! I appreciate the time. We can have the error handler "download" (I'm actually not sure what the async is doing) the response body. We typically don't take additional action on exception, simply log them in case we need to investigate an API issue so I thought maybe we could bake that in a bit more elegantly but maybe it's a niche thing to do so. |
I guess one follow up point, you say that 1 & 2 are one-liners, but they aren't really because we don't want to unintentionally throw a different exception in the handler due to calling 1/2. They can most definitely throw an exception because I recently was experiencing that. That's why my snippet has that wrapped in a try-catch to swallow it. We can for sure make an extension method or some other utility to make it a one-liner though. |
I'm going to leave this open and think on it some more. I'm starting to see your point that if something up the stack is handling errors generically (such as by logging them), it's probably common that you'd want the body of an error response in the exception Message somehow. There may still be a better way to solve this via the event handler, but I'll come back to this at some point. |
Forgive me if there is a way to do this within the Flurl library already. If so, I'll gladly take your advice on a better solution :)
We have code that looks like this as it's pretty difficult to debug a failed request without reading the response:
It would be a great enhancement if the
FlurlHttpException
or even the initial request fluent API had a way to automatically enable this exception handling. Something like:Or via the fluent API:
It may also need some features to allow deserializing the error response as well, but for my situation reading it as a string is all I need.
The text was updated successfully, but these errors were encountered: