|
|
|
@ -7,7 +7,11 @@
|
|
|
|
|
*/
|
|
|
|
|
package com.base;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
@ -36,19 +40,23 @@ public class BaseController {
|
|
|
|
|
* @see [类、类#方法、类#成员]
|
|
|
|
|
*/
|
|
|
|
|
@ExceptionHandler
|
|
|
|
|
public Object exp(HttpServletRequest request, Exception ex) {
|
|
|
|
|
|
|
|
|
|
public Object exp(HttpServletRequest request, HttpServletResponse response,Exception ex) {
|
|
|
|
|
System.out.println("URI"+request.getRequestURI());
|
|
|
|
|
request.setAttribute("ex", ex);
|
|
|
|
|
System.err.println("BaseController --exp ");
|
|
|
|
|
// 根据不同错误转向不同页面
|
|
|
|
|
if(ex instanceof CustomException) {
|
|
|
|
|
CustomException cuse = (CustomException) ex;
|
|
|
|
|
log.error(Configs.GLOBAL_EXP_CUSTOM);
|
|
|
|
|
//TODO 从新封装json
|
|
|
|
|
return "{"+Configs.GLOBAL_EXP_CUSTOM+":"+cuse.getMsg()+"}";
|
|
|
|
|
Map<String, String> errmsg = new HashMap<>();
|
|
|
|
|
errmsg.put("code", cuse.getCode());
|
|
|
|
|
errmsg.put("msg", cuse.getMsg());
|
|
|
|
|
log.error(cuse.getCode());
|
|
|
|
|
response.setStatus(500);
|
|
|
|
|
return errmsg;
|
|
|
|
|
} else {
|
|
|
|
|
//TODO 其他错误则 调到指定页面
|
|
|
|
|
//其他错误则 调到指定页面
|
|
|
|
|
log.error(Configs.GLOBAL_EXP_NOT_CUSTOM, ex);
|
|
|
|
|
response.setStatus(500);
|
|
|
|
|
return "error";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|