use of com.dq.easy.cloud.module.exception.bo.DqBaseBusinessException in project dq-easy-cloud by dq-open-cloud.
the class DqBaseExceptionHandle method handleAndReturnData.
/**
* 基于@ExceptionHandler异常处理
*/
@ExceptionHandler
@ResponseBody
public DqBaseServiceResult handleAndReturnData(HttpServletRequest request, HttpServletResponse response, Exception ex) {
logger.error(ex.getMessage(), ex);
DqBaseServiceResult dqBaseServiceResult = DqBaseServiceResult.newInstance();
DqBaseServiceResultException serviceResultException = DqBaseServiceResultException.newInstance();
String path = request.getRequestURL().toString();
if (ex instanceof DqBaseBusinessException) {
DqBaseBusinessException dbbException = (DqBaseBusinessException) ex;
dqBaseServiceResult.buildErrorCodeAndMsg(dbbException.getErrorCode(), dbbException.getErrorMsg());
} else if (ex instanceof RuntimeException) {
dqBaseServiceResult.buildDqBaseErrorCodeInf(DqBaseErrorCodeEnum.RUNTIME_EXCEPTION);
} else {
dqBaseServiceResult.buildDqBaseErrorCodeInf(DqBaseErrorCodeEnum.SYS_EXCEPTION);
}
serviceResultException.setException(ex.getClass().getName());
serviceResultException.setFailureDetails(ex.getMessage());
serviceResultException.setTimstamp(DqDateUtils.getCurrentDate());
serviceResultException.setPath(path);
dqBaseServiceResult.buildServiceResultException(serviceResultException);
DqLogUtils.error("异常统一处理日志", dqBaseServiceResult, logger);
return dqBaseServiceResult;
}
Aggregations