Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/docs/asciidoc/web/webflux.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2266,9 +2266,20 @@ configure or customize message readers.
You can use `@RequestBody` in combination with `javax.validation.Valid` or Spring's
`@Validated` annotation, which causes Standard Bean Validation to be applied.
By default, validation errors cause a `WebExchangeBindException`, which is turned
into a 400 (`BAD_REQUEST`) response. Alternatively, you can handle validation errors locally
within the controller through an `Errors` or a `BindingResult` argument. The following
example uses a `BindingResult` argument`:
into a 400 (`BAD_REQUEST`) response.

[source,java,indent=0]
[subs="verbatim,quotes"]
----
@ExceptionHandler(WebExchangeBindException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public Mono<T> processValidationError(WebExchangeBindException ex) {
//..
}
----

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear what you mean with this update. The paragraph above talks about the built-in, exception handling that happens by default and does not require the sample code shown, which shows how to handle the exception explicitly to the same effect..


The following example uses a `BindingResult` argument :

[source,java,indent=0]
[subs="verbatim,quotes"]
Expand All @@ -2279,6 +2290,9 @@ example uses a `BindingResult` argument`:
}
----

And throws following exception :

`java.lang.IllegalStateException: An Errors/BindingResult argument is expected immediately after the @ModelAttribute argument to which it applies. For @RequestBody and @RequestPart arguments, please declare them with a reactive type wrapper and use its onError operators to handle WebExchangeBindException`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong to me. The sample above shows how use BindingResult correctly. It shouldn't cause an ISE.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you tried this pice of code?

@flezsoftware flezsoftware May 20, 2019

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasted couple of hours for make @RequestBody and BindingResult run in @RestController with this part from documentation. Not successful -> spring-boot-starter-webflux 2.2.0.M3

[[webflux-ann-httpentity]]
==== `HttpEntity`
Expand Down