Flurl icon indicating copy to clipboard operation
Flurl copied to clipboard

Serialization based on response status code

Open mweel1 opened this issue 1 year ago • 1 comments

A common use case is that you send a request to the API and it comes back with an 400 status and a difference type of JSON then you might have expected with say a 200.

What do you think about adding functionality that would allow us to do something like

.WhenStatus(400)
   .ReceiveJson<ValidationResponse>();

mweel1 avatar Jul 26 '24 17:07 mweel1

If that's part of the same fluent call chain as when you specify a different type for 200 responses, then what's the overall return type of the call? Task<object>? I think it would have to be, because the actual return type can't be known at runtime.

There's already 3 patterns for handing error responses: try/catch, inspecting FlurlResponse, and handling OnError. I'm not sure we need to introduce another way.

tmenier avatar Aug 02 '24 18:08 tmenier