use of com.dtstack.taier.common.exception.ExceptionEnums in project Taier by DTStack.
the class ResponseAdvisor method exceptionHandler.
@ResponseBody
@ExceptionHandler(value = Throwable.class)
public R exceptionHandler(Throwable e) {
ExceptionEnums errorCode = ErrorCode.UNKNOWN_ERROR;
String errorMsg = null;
RdosDefineException rdosDefineException = null;
if (e.getCause() instanceof DtCenterDefException) {
rdosDefineException = (RdosDefineException) e.getCause();
if (rdosDefineException.getErrorCode() != null) {
errorCode = rdosDefineException.getErrorCode();
}
errorMsg = rdosDefineException.getErrorMsg();
if (e.getCause().getCause() != null) {
LOGGER.error("", e.getCause().getCause());
}
} else if (e instanceof RdosDefineException) {
rdosDefineException = (RdosDefineException) e;
if (rdosDefineException.getErrorCode() != null) {
errorCode = rdosDefineException.getErrorCode();
}
errorMsg = rdosDefineException.getErrorMsg();
if (e.getCause() != null) {
LOGGER.error("", e.getCause());
}
} else {
errorCode = ErrorCode.SERVER_EXCEPTION;
errorMsg = ErrorCode.SERVER_EXCEPTION.getDescription();
LOGGER.error("", e);
}
if (errorCode.equals(ErrorCode.PERMISSION_LIMIT)) {
return R.fail(errorCode.getCode(), errorMsg);
}
return R.fail(errorCode.getCode(), errorMsg);
}
use of com.dtstack.taier.common.exception.ExceptionEnums in project Taier by DTStack.
the class ResponseAdvisor method handleValidationException.
/**
* ValidationException
*/
@ResponseBody
@ExceptionHandler(BindException.class)
public R handleValidationException(BindException e) {
ExceptionEnums errorCode = ErrorCode.UNKNOWN_ERROR;
BindingResult bindingResult = e.getBindingResult();
List<FieldError> fieldErrors = bindingResult.getFieldErrors();
StringBuilder message = new StringBuilder();
for (FieldError fieldError : fieldErrors) {
message.append(fieldError.getField()).append(":").append(fieldError.getDefaultMessage()).append(",");
}
return R.fail(errorCode.getCode(), message.toString());
}
Aggregations