即使在禁用时,Micronaut的HTTP客户端也会继续投掷httpclientResponseException
我有一个简单的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 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论