use of com.jim.framework.web.common.ErrorInfo in project jim-framework by jiangmin168168.
the class BaseController method exception.
@ExceptionHandler
public ValueResult exception(HttpServletRequest request, Exception ex) {
ValueResult result = new ValueResult();
if (ex instanceof ConstraintViolationException) {
ConstraintViolationException constraintViolationException = (ConstraintViolationException) ex;
Set<ConstraintViolation<?>> constraintViolations = constraintViolationException.getConstraintViolations();
String errorMsg = this.getConstraintViolationsMsg(constraintViolations);
result.setError(new ErrorInfo(ErrorDef.InvalidParameters.getCode(), errorMsg));
result.setResult(false);
} else if (ex instanceof MethodArgumentNotValidException) {
MethodArgumentNotValidException methodArgumentNotValidException = (MethodArgumentNotValidException) ex;
List<ObjectError> allErrors = methodArgumentNotValidException.getBindingResult().getAllErrors();
String errorMsg = this.getAllParametersInValidMsg(allErrors);
result.setError(new ErrorInfo(ErrorDef.InvalidParameters.getCode(), errorMsg));
} else {
logger.error("system error", ex);
result.setError(new ErrorInfo(ErrorDef.ServerError.getCode(), ex.getMessage()));
result.setResult(false);
}
return result;
}
Aggregations