micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.07k stars 1.07k forks source link

StreamingHttpClient jsonStream doesn't read the body on error #1438

Closed errrrk closed 3 years ago

errrrk commented 5 years ago

@graemerocher suggested to create this bug report.

See also https://gitter.im/micronautfw/questions?at=5c9a35b12fb6800d8083f9f0

Task List

Steps to Reproduce

  1. Run test (see gist below)
  2. Http client makes call, server responds with 400 and json body
  3. Register an onErrorResumeNext() on the call. Try to read json body

Expected Behaviour

When reading JSON body in onErrorResumeNext() I'd expect the response to have the JSON body available. In this particular case because I want to read an error code from the JSON body and take a different course of action in case of a specific error code.

Actual Behaviour

When reading JSON body in onErrorResumeNext() the response is Optional.empty.

Environment Information

Example Application

https://gist.github.com/errrrk/821386de19ec016aa0b7dc4668431785

jameskleeh commented 5 years ago

@errrrk A gist of the test case is a good starting point, however since I can't run that without the surrounding code it is less than ideal for debugging the issue.

jameskleeh commented 5 years ago

@errrrk The current design of jsonStream is to ignore the body for failed requests. If you use the standard retrieve/exchange it works as you expect

errrrk commented 5 years ago

Gist - Clear and apologies. Mostly due to time constraints on my side.

retrieve/exchange - Thanks, I'll give that a try.

jameskleeh commented 3 years ago

If the error type is provided via the @Client annotation, the body will now be read on error