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);
}
Aggregations