refit
refit copied to clipboard
[BUG] ApiException.Content is `null` when the HttpResponseMessage.Content is a Stream
Describe the bug
When an ApiException occurs (in my case an error while deserializing causing a JsonException), and the response.Content is a Stream, then the ApiException that gets thrown has null for its Content. I'm guessing this is because of the one-way reading of the response stream?
Steps To Reproduce If you were to alter the existing WithHtmlResponse_ShouldReturnApiException test to instead use a StreamContent, You will see that the test will start to fail.
var expectedResponse = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes(htmlResponse)))
};
Expected behavior I understand the benefit of one-way stream reading, but it would be super beneficial to be able to see the response content when an error occurred trying to deserialize it.
A year today! I just ran into this too, is there a work around so I can see what the deserialising issue actually is?
I don't remember researching a workaround, sorry. At the time, since I knew it was a deserialization issue, I think I just fixed the JSON and moved on after creating this bug issue.