qa-prevention-gwj/src/main/java/com/zcloud/config/ExceptionConfiguration.java

43 lines
1.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.zcloud.config;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
/**
* 说明:错误异常拦截处理
* 作者luoxiaobao
* 官网www.qdkjchina.com
*/
@Configuration
public class ExceptionConfiguration implements HandlerExceptionResolver {
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
Exception ex) {
ModelAndView mv = new ModelAndView(new MappingJackson2JsonView()); //返回json
String exInfo = ex.toString().replaceAll("\n", "<br/>");
boolean status = exInfo.contains("Subject does not have permission");
if(status){
exInfo = "[没有此页面的访问权限]" + exInfo;
}else {
System.out.println("==============异常开始=============");
ex.printStackTrace();
System.out.println("==============异常结束=============");
}
mv.addObject("exception", exInfo);
mv.addObject("result", "exception");
return mv;
}
}