Search in sources :

Example 1 with IEnums

use of com.duangframework.core.common.enums.IEnums in project duangframework by tcrct.

the class BaseController method returnFailJson.

/**
 * 返回错误信息到客户端
 *
 * @param ex
 *            自定义ServiceException异常
 */
protected void returnFailJson(Exception ex) {
    String message = ex.getMessage();
    int code = IEnums.IENUMS_FAIL_CODE;
    if (ex instanceof ServiceException) {
        ServiceException se = (ServiceException) ex;
        IEnums enums = se.getEnums();
        if (ToolsKit.isEmpty(enums)) {
            code = ToolsKit.isEmpty(se.getCode()) ? IEnums.IENUMS_FAIL_CODE : se.getCode();
            message = ToolsKit.isEmpty(se.getMessage()) ? IEnums.IENUMS_FAIL_MESSAGE : se.getMessage();
        } else {
            code = enums.getCode();
            message = enums.getMessage();
        }
        ToolsKit.console("returnFail:" + se.getStackTrace()[0].getClassName() + "-->" + se.getStackTrace()[0].getMethodName() + "-->" + se.getStackTrace()[0].getLineNumber() + ":" + message + ":" + request.getRequestURI() + ":" + JSON.toJSONString(getAllParams()));
    } else {
        logger.warn(ex.getMessage(), ex);
    }
    ReturnDto<Map<String, Object>> dto = new ReturnDto<Map<String, Object>>();
    HeadDto head = ToolsKit.getThreadLocalDto();
    if (ToolsKit.isEmpty(head)) {
        head = new HeadDto();
        head.setUri(request.getRequestURI());
    }
    head.setRet(code);
    head.setMsg(message);
    dto.setHead(head);
    dto.setData(getAllParams());
    returnJson(dto);
}
Also used : HeadDto(com.duangframework.core.common.dto.result.HeadDto) ServiceException(com.duangframework.core.exceptions.ServiceException) IEnums(com.duangframework.core.common.enums.IEnums) ReturnDto(com.duangframework.core.common.dto.result.ReturnDto) JSONObject(com.alibaba.fastjson.JSONObject)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)1 HeadDto (com.duangframework.core.common.dto.result.HeadDto)1 ReturnDto (com.duangframework.core.common.dto.result.ReturnDto)1 IEnums (com.duangframework.core.common.enums.IEnums)1 ServiceException (com.duangframework.core.exceptions.ServiceException)1