Flurl: FlurlHttpException.GetResponseString() returns null when the inner exception is a Json exception
Hi, I’m not sure if this is a normal behaviour, but it appears that when the JSON deserialization fails with an exception, the wrapped FlurlHttpException doesn’t give access to the raw response content string.
The following code reproduces the issue:
Url url = "https://reqres.in/api/users";
try
{
await url.GetJsonAsync<List<int>>();
}
catch (FlurlHttpTimeoutException)
{
Debugger.Break();
}
catch (FlurlHttpException ex)
{
string rawResponseContent = ex.GetResponseString();
Debugger.Break();
}
The InnerException of ex is a Newtonsoft.Json.JsonSerializationException that says that the response content cannot be deserialized because it doesn’t match the given T, and that’s fine.
But the call to ex.GetResponseString() returns null. I think the request should be considered as failed when there’s a deserialization error, so that GetResponseString() actually returns something that can be logged, or maybe attempted to be parsed as an error…
Thanks.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (7 by maintainers)
Commits related to this issue
- #299 & #288 better exception handling for parsing errors — committed to tmenier/Flurl by tmenier 6 years ago
Working fine here 😊