|
|
|
@ -16,7 +16,10 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
|
|
|
|
import com.platform.utils.Configs;
|
|
|
|
|
|
|
|
|
@ -28,6 +31,7 @@ import com.platform.utils.Configs;
|
|
|
|
|
* @see [相关类/方法]
|
|
|
|
|
* @since [产品/模块版本]
|
|
|
|
|
*/
|
|
|
|
|
@ControllerAdvice
|
|
|
|
|
public class BaseController {
|
|
|
|
|
|
|
|
|
|
/** log4j */
|
|
|
|
@ -41,28 +45,34 @@ public class BaseController {
|
|
|
|
|
* @return
|
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
|
*/
|
|
|
|
|
@ExceptionHandler
|
|
|
|
|
@ExceptionHandler
|
|
|
|
|
@ResponseBody
|
|
|
|
|
public Object exp(HttpServletRequest request, HttpServletResponse response,Exception ex) {
|
|
|
|
|
log.error("URI"+request.getRequestURI());
|
|
|
|
|
log.error("BaseController --exp " + ex);
|
|
|
|
|
new CustomException("base_code_", ex);
|
|
|
|
|
// 根据不同错误转向不同页面
|
|
|
|
|
ModelMap modelMap = new ModelMap ();
|
|
|
|
|
Map<String, String> errmsg = new HashMap<>();
|
|
|
|
|
if(ex instanceof CustomException) {
|
|
|
|
|
//返回异常信息
|
|
|
|
|
ModelMap modelMap = new ModelMap();
|
|
|
|
|
CustomException cuse = (CustomException) ex;
|
|
|
|
|
Map<String, String> errmsg = new HashMap<>();
|
|
|
|
|
errmsg.put("code", cuse.getCode());
|
|
|
|
|
errmsg.put("msg", cuse.getMsg());
|
|
|
|
|
log.error(cuse.getCode());
|
|
|
|
|
errmsg.put("err", "网络问题请稍后再试!");
|
|
|
|
|
// request.setAttribute("msg", cuse.getMsg());
|
|
|
|
|
// request.setAttribute("err", "网络问题请稍后再试!");
|
|
|
|
|
modelMap.addAllAttributes(errmsg);
|
|
|
|
|
log.error(cuse.getCode());
|
|
|
|
|
response.setStatus(500);
|
|
|
|
|
return modelMap;
|
|
|
|
|
} else {
|
|
|
|
|
//其他错误则 调到指定页面
|
|
|
|
|
log.error(Configs.GLOBAL_EXP_NOT_CUSTOM, ex);
|
|
|
|
|
response.setStatus(500);
|
|
|
|
|
return response;
|
|
|
|
|
errmsg.put("err", "系统问题请稍后再试!");
|
|
|
|
|
modelMap.addAllAttributes(errmsg);
|
|
|
|
|
return modelMap;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|