Commit 80ad8951 by guojx

RestResponse统一异常处理

parent eeeaccb5
package com.gic.haoban.manage.web.exception;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.haoban.base.api.common.ShowFrontMessageException;
import com.gic.haoban.common.utils.HaobanResponse;
import com.gic.haoban.manage.web.controller.WebBaseController;
......@@ -52,6 +53,25 @@ public class GlobalExceptionHandler extends WebBaseController {
return res;
}
@ResponseBody
@ExceptionHandler(RuntimeException.class)
public RestResponse controllerRunExceptionForRest(HttpServletResponse response, RuntimeException ex) {
logger.error("controllerRunException:{}", ex.getMessage(), ex);
RestResponse res = new RestResponse();
res.setCode(String.valueOf(HaoBanErrCode.ERR_3.getCode()));
String message = ex.getMessage();
if (message != null && message.indexOf(ShowFrontMessageException.class.getName()) > -1) {
Matcher matcher = pattern.matcher(message);
while (matcher.find()) {
message = (matcher.group(2));
}
} else {
message = HaoBanErrCode.ERR_3.getMsg();
}
res.setMessage(message);
return res;
}
/**
* 全局异常
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment