use of org.apache.shiro.authc.UnknownAccountException in project Workload by amoxu.
the class CustomExceptionResolver method resolveException.
public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
ModelAndView modelAndView = new ModelAndView();
com.hfut.exception.CustomException customException;
e.printStackTrace();
if (e instanceof CustomException) {
customException = (CustomException) e;
} else if (e instanceof UnknownAccountException) {
// 用户名错误异常
modelAndView.addObject("message", "{\"status\":1,\"msg\":\"用户不存在\"}");
modelAndView.setViewName("error");
return modelAndView;
} else if (e instanceof IncorrectCredentialsException) {
// 用户名密码异常
modelAndView.addObject("message", "{\"status\":1,\"msg\":\"密码错误\"}");
modelAndView.setViewName("error");
return modelAndView;
} else if (e instanceof NullPointerException) {
customException = new com.hfut.exception.CustomException("必填选项不能为空!");
e.printStackTrace();
} else {
customException = new com.hfut.exception.CustomException("未知错误");
e.printStackTrace();
}
// 错误信息
String message = customException.getMessage();
// 错误信息传递和错误页面跳转
modelAndView.addObject("message", message);
modelAndView.setViewName("error");
return modelAndView;
}
Aggregations