-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Update webflux.adoc #22993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update webflux.adoc #22993
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
| //.. | ||
| } | ||
| ---- | ||
|
|
||
| The following example uses a `BindingResult` argument : | ||
|
|
||
| [source,java,indent=0] | ||
| [subs="verbatim,quotes"] | ||
|
|
@@ -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` | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you tried this pice of code?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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` | ||
|
|
||
There was a problem hiding this comment.
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..