refit icon indicating copy to clipboard operation
refit copied to clipboard

[BUG] ApiException.Content is `null` when the HttpResponseMessage.Content is a Stream

Open rhullah opened this issue 4 years ago • 2 comments

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.

rhullah avatar Oct 19 '21 17:10 rhullah

A year today! I just ran into this too, is there a work around so I can see what the deserialising issue actually is?

mattheys avatar Oct 19 '22 15:10 mattheys

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.

rhullah avatar Oct 19 '22 17:10 rhullah