即使在禁用时,Micronaut的HTTP客户端也会继续投掷httpclientResponseException

发布于 2025-01-22 20:22:00 字数 1548 浏览 3 评论 0原文

我有一个简单的micronaut 3.4.2应用程序。我正在尝试使用httpclient来测试某些(HTTP)资源。我已经禁用了投掷httpclientResponseException的响应的默认行为,但是无论如何,我仍然会得到例外。

这是application-test.yaml ../ src/test/test/resources/的内容:

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

测试用例看起来像:

@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)
  }
}

基于 this 拉动请求,带有micronaut.http.client.client.exception.exception-on-on-eror-eror-eror-eror-eror-eror-eror-eror-eror-ror-状态设置为false它应该起作用。

我是否缺少某些东西?还是不支持?还有其他解决方案吗?我不想使用任何其他HTTP客户端。


更新

i 在他们的问题跟踪器中打开了一个问题

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文