RecoveryInterceptor throw exception for bad request #7558
-
I'm trying to use Micronaut with Reactor but I faced problems with returning errors.
I'm trying to do something like this: @Post(uri = "/test")
fun test(
@Body dto: Dto
): Publisher<HttpResponse<Unit>> {
return Mono.from(service.test(dto))
.map { HttpResponse.ok(it) }
.defaultIfEmpty(HttpResponse.notFound())
.onErrorResume(TestException::class.java) { exception ->
Mono.just(HttpResponse.badRequest(JsonError(exception.message)))
}
} And call it by Micronaut declarative client: @Client
@CircuitBreaker
@Headers(Header(name = ACCEPT, value = "application/json"))
interface MyClient {
@Post("/test")
fun test(
@Body dto: Dto
):HttpResponse<Any>
} But in this case, RecoveryInterceptor still throws an exception instead of returning just BAD_REQUEST. If I use OK, Miccronaut returns status correctly:
but not for BadRequest
Am I doing something wrong? Is it a bug? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Looks like it happens here: https://github.com/micronaut-projects/micronaut-core/blob/3.5.x/http-client/src/main/java/io/micronaut/http/client/netty/DefaultHttpClient.java#L3275 |
Beta Was this translation helpful? Give feedback.
-
According to the documentation https://docs.micronaut.io/latest/guide/#lowLevelClientError
It might be a good idea to have some option in |
Beta Was this translation helpful? Give feedback.
According to the documentation https://docs.micronaut.io/latest/guide/#lowLevelClientError
It might be a good idea to have some option in
@Client(throwOnError = false)
to allow receivingHttpResponse
when status is >= 400. WDYT @graemerocher @yawkat