question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

http-client: support returning http response without exception when status >= 400

See original GitHub issue

Task 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

  1. With HttpClient, query an endpoint that returns a status code >= 400
  2. 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:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
fabienrenaudcommented, Nov 10, 2019

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…

4reactions
graemerochercommented, Oct 3, 2019

I think rather than making it configurable it should be another method on the HttpClient interface

Read more comments on GitHub >

github_iconTop Results From Across the Web

Web API Read Response on 400 - Stack Overflow
HttpClient does not throw an exception when the HTTP response contains an error code. Instead, the IsSuccessStatusCode property is false if ...
Read more >
400 Bad Request Error: What It Is and How to Fix It
The 400 Bad Request Error is an HTTP response status code indicating that the server was unable to process the request sent by...
Read more >
400 Bad Request - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request ......
Read more >
Handling Exceptions Returned from the Web API
When you return an OK from your method, a 200 HTTP status code is returned, which signifies that no error has occurred.
Read more >
Handling Exceptions Using the Angular HttpClient Service
throwError . First, update your BooksService to throw a custom error depending on the final status of the HTTP request. ; BooksComponent to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found