HttpClient, query an endpoint that returns a status code >= 400HttpClientResponseException is thrownio.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)
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.
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
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
I think rather than making it configurable it should be another method on the HttpClient interface
It would be nice to have it configurable for declarative http clients.
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...
@graemerocher Would it be acceptable to modify behavior (for 1.3.x) of the existing exchange methods to not throw an exception when bodyType == errorType ? This would preserve most of the existing default behaviors (since errorType is always different than bodyType by default).
From a usage standpoint, there is no reason to throw an exception when the bad response can gracefully be decoded (and returned) without triggering an alternate flow...
This turned out to be a trivial change: https://github.com/micronaut-projects/micronaut-core/pull/2372
Most helpful comment
Is this something that could be added soon?
Writing tests for error cases (code ≥ 400) using
HttpClientis 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...