Search in sources :

Example 1 with DqBaseServiceResultException

use of com.dq.easy.cloud.module.exception.dto.DqBaseServiceResultException 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;
}
Also used : DqBaseServiceResultException(com.dq.easy.cloud.module.exception.dto.DqBaseServiceResultException) DqBaseBusinessException(com.dq.easy.cloud.module.exception.bo.DqBaseBusinessException) DqBaseServiceResult(com.dq.easy.cloud.module.basic.pojo.dto.DqBaseServiceResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DqBaseServiceResult (com.dq.easy.cloud.module.basic.pojo.dto.DqBaseServiceResult)1 DqBaseBusinessException (com.dq.easy.cloud.module.exception.bo.DqBaseBusinessException)1 DqBaseServiceResultException (com.dq.easy.cloud.module.exception.dto.DqBaseServiceResultException)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1