Search in sources :

Example 1 with EcBaseServiceResultException

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;
}
Also used : EcBaseServiceResultException(com.easy.cloud.core.exception.dto.EcBaseServiceResultException) EcBaseServiceResult(com.easy.cloud.core.basic.pojo.dto.EcBaseServiceResult) EcBaseBusinessException(com.easy.cloud.core.exception.bo.EcBaseBusinessException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

EcBaseServiceResult (com.easy.cloud.core.basic.pojo.dto.EcBaseServiceResult)1 EcBaseBusinessException (com.easy.cloud.core.exception.bo.EcBaseBusinessException)1 EcBaseServiceResultException (com.easy.cloud.core.exception.dto.EcBaseServiceResultException)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1