use of com.easy.cloud.core.exception.dto.EcBaseServiceResultException in project dq-easy-cloud by dq-open-cloud.
the class EcBaseExceptionHandle method handleAndReturnData.
/**
* 基于@ExceptionHandler异常处理
*/
@ExceptionHandler
@ResponseBody
public EcBaseServiceResult handleAndReturnData(HttpServletRequest request, HttpServletResponse response, Exception ex) {
logger.error(ex.getMessage(), ex);
EcBaseServiceResult ecBaseServiceResult = EcBaseServiceResult.newInstance();
EcBaseServiceResultException serviceResultException = EcBaseServiceResultException.newInstance();
String path = request.getRequestURL().toString();
if (ex instanceof EcBaseBusinessException) {
EcBaseBusinessException dbbException = (EcBaseBusinessException) ex;
ecBaseServiceResult.buildErrorCodeAndMsg(dbbException.getErrorCode(), dbbException.getErrorMsg());
} else if (ex instanceof RuntimeException) {
ecBaseServiceResult.buildDqBaseErrorCodeInf(EcBaseErrorCodeEnum.RUNTIME_EXCEPTION);
} else {
ecBaseServiceResult.buildDqBaseErrorCodeInf(EcBaseErrorCodeEnum.SYS_EXCEPTION);
}
serviceResultException.setException(ex.getClass().getName());
serviceResultException.setFailureDetails(ex.getMessage());
serviceResultException.setTimstamp(EcDateUtils.getCurrentDate());
serviceResultException.setPath(path);
ecBaseServiceResult.buildServiceResultException(serviceResultException);
EcLogUtils.error("异常统一处理日志", ecBaseServiceResult, logger);
return ecBaseServiceResult;
}
Aggregations