http-client: support returning http response without exception when status >= 400
See original GitHub issueTask List
- Steps to reproduce provided
- Stacktrace (if present) provided
- Example that reproduces the problem uploaded to Github
- Full description of the issue provided (see below)
Steps to Reproduce
- With
HttpClient
, query an endpoint that returns a status code >= 400 - Notice
HttpClientResponseException
is thrown
io.micronaut.http.client.exceptions.HttpClientResponseException: Conflict
at io.micronaut.http.client.DefaultHttpClient$10.channelRead0(DefaultHttpClient.java:1821)
at io.micronaut.http.client.DefaultHttpClient$10.channelRead0(DefaultHttpClient.java:1761)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
Expected Behaviour
Need HttpClient implementation that does not create nor throw an exception when full response has been received and status code >= 400.
This should be a configurable option in HttpClientConfiguration
.
Actual Behaviour
DefaultHttpClient
always throw HttpClientResponseException
when status code is >= 400.
https://github.com/micronaut-projects/micronaut-core/blob/master/http-client/src/main/java/io/micronaut/http/client/DefaultHttpClient.java#L1807
Environment Information
- Operating System: Mac OS 10.14.6 (mojave)
- Micronaut Version: 1.2.3
- JDK Version: Oracle JDK 1.8.0_181
Example Application
Code identical to Mocking Collaborators official test example: https://micronaut-projects.github.io/micronaut-test/latest/guide/index.html#_mocking_collaborators but with the endpoint returning an error.
Micronaut code throwing the exception: https://github.com/micronaut-projects/micronaut-core/blob/master/http-client/src/main/java/io/micronaut/http/client/DefaultHttpClient.java#L1807
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:5 (5 by maintainers)
Is this something that could be added soon? Writing tests for error cases (code ≥ 400) using
HttpClient
is very cumbersome at the momen. I had to define some nasty utility methods to try/catch every call to work around this … I’d like to make micronaut mainstream on my team soon and not have to tell everyone to rewrite all their tests (to remove the utility methods) in 6 months when this ships…I think rather than making it configurable it should be another method on the
HttpClient
interface