Affects: \
I write a simple demo below, I write a Controller with a handler method receiving a post request and consume a valid request body
@RestController
class Controller {
@PostMapping("/test")
fun test(@RequestBody @Valid foo: Foo) {
println(foo)
}
@ExceptionHandler(Exception::class)
fun handleException(e: Exception) {
println(e)
}
}
data class Foo(
@field:NotEmpty
val name: String
)
Then I send a post request with this body to the application.
{
"name": ""
}
Check out the console and you can see a exception printed and it's type is WebExchangeBindException
But according to the spring document validation, it should throw a MethodArgumentNotValidException
.
I also test this behavior in mvc and it's the expected exception.
Comment From: snicoll
Check out the console
It looks like you'd like us to run the example to actually see the error. Please don't paste code in text like that as the only choice we have is to copy it in a small project created from start.spring.io in the hope we're not missing another piece you're not showing. I haven't looked at the actual code, but please edit your description to replace that with a reference to an actual sample. You can attach a zip to this issue or push the code to a GitHub repository.
Comment From: xinxiong-tw
spring-kotlin-webflux-playground.zip @snicoll Sorry, here is the code in zip.
Comment From: snicoll
Thanks. I've reproduced what you've described, we'll look into it.
Comment From: imvtsl
Hi @snicoll I would like to begin contributing to spring framework. Do you mind assigning this to me?
Comment From: snicoll
@imvtsl thanks for the offer but I am not sure yet what we want to do for this. While the issue title makes it sound like a documentation change, it might not be. You can see this by the "waiting-for-triage" label that means the team hasn't really determined the nature of the issue yet.
Comment From: xinxiong-tw
@snicoll @imvtsl
While the issue title makes it sound like a documentation change
Maybe I didn't make it clean, IMO I would like this exception to be type of MethodArgumentNotValidException
. Because in webmvc it's this exception type and align with the doc.
Comment From: snicoll
I understood what you reported but I am not sure what we should do. @rstoyanchev should know.
Comment From: rstoyanchev
WebExchangeBindException
is the expected exception for WebFlux. It is a ResponseStatusException
as other exceptions in WebFlux and BindingResult
is implemented as an interface only. MethodArgumentNotValidException
on the other hand extends BindException
and inherits the BindingResult
implementation. In short, I confirm that it is a documentation issue.