I am trying to capture the Spring annotation(@NotBlank, @Pattern, etc) errors in Errors class and throwing error if it is not empty.
@PostMapping("/nodes")
public ResponseEntity<List<SagaInfo>> createNode(@Valid NodePostRequest nodePostRequest, Errors errors) {
if (errors.hasErrors()) {
//collect errors in collection
//throw custom exception
}
}
This Errors.class fields are showing on swagger and I don't want that to happen. I don't know any annotation that works. I have also tried to add handleMethodArgumentNotValid in a custom class with @ControllerAdvice to handle the errors, but somehow the errors are not caught there.
Any thoughts?