Micronaut's HTTP client keeps throwing HttpClientResponseException even when disabled

2k Views Asked by At

I have a simple Micronaut 3.4.2 application. I'm trying to use the HttpClient to test some (HTTP) resources. I've disabled the default behavior for responses that throw HttpClientResponseException, but still, I'm getting that exception back no matter what.

This is the content of application-test.yaml under ../src/test/resources/:

micronaut:
  http:
    client:
      exception-on-error-status: false
  server:
    port: -1

The test case looks like:

@MicronautTest(environments = [Environment.TEST])
internal class ControllerTest {
  @Inject
  @field:Client("/api/resource")
  private lateinit var client: HttpClient

  @Test
  fun get_WhenRecordDoesNotExist() {
    val id = UUID.randomUUID()
    val request = HttpRequest.GET<Customer>("/$id").accept(MediaType.APPLICATION_JSON_TYPE)
    val response = client.toBlocking().exchange(request, String::class.java)
    Assertions.assertThat(response.status).isEqualTo(HttpStatus.NOT_FOUND)
  }
}

Based on this pull request, with micronaut.http.client.exception-on-error-status set to false it should work.

Am I missing something or is this still not supported? Are there any other solutions for this — I wouldn't like to use any other HTTP client.


UPDATE

I opened an issue in their issue tracker for this.

0

There are 0 best solutions below