@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public XAPIErrorInfo handleMethodArgumentNotValidException(final HttpServletRequest request, MethodArgumentNotValidException e) {
final List<String> errorMessages = new ArrayList<String>();
for (ObjectError oe : e.getBindingResult().getAllErrors()) {
if (oe instanceof FieldError) {
final FieldError fe = (FieldError)oe;
final String msg = String.format(
"Field error in object '%s' on field '%s': rejected value [%s].", fe.getObjectName(), fe.getField(), fe.getRejectedValue());
errorMessages.add(msg);
} else {
errorMessages.add(oe.toString());
}
}
final XAPIErrorInfo result = new XAPIErrorInfo(HttpStatus.BAD_REQUEST, request, errorMessages);
this.logException(e);
this.logError(result);
return result;
}
XAPIExceptionHandlerAdvice.java 文件源码
java
阅读 39
收藏 0
点赞 0
评论 0
项目:OpenLRW
作者:
评论列表
文章目录