Spring MVC and JSR 303 Validation error customization
DougBreaux 270007SMYJ Visits (2488)
Brief follow-up to Spri
Wanting to improve on the default error messages. The article Spri
For me, adding an @ExceptionHandler method to an existing common base Controller class was an easy, straightforward option.
List<ErrorResponse> errors = new ArrayList<>();
for (FieldError f: e.ge
Where ErrorResponse is a POJO I defined that has int code and String message fields.
(I'm still deciding whether to always return a List, whether to use the same 400 code for each error as for the overall response, etc. I think I might switch the "code" to String with the field name. Best-practice opinions and pointers welcome, but that's not the point of this post.)
Which can generate a response like: