全局异常exp方法修改

glusterfs-api
chenlw 9 years ago
parent 91268a91e9
commit e0860af5fc

@ -1,55 +1,63 @@
/** /**
* BaseController.java * BaseController.java
* : XX * : XX
* : <> * : <>
* 201697 * 201697
* <> * <>
*/ */
package com.base; package com.base;
import javax.servlet.http.HttpServletRequest; import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ExceptionHandler; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.platform.utils.Configs;
import org.apache.log4j.Logger;
/** import org.springframework.web.bind.annotation.ExceptionHandler;
* <>
* <> import com.platform.utils.Configs;
* @author chen
* @version [201697] /**
* @see [/] * <>
* @since [/] * <>
*/ * @author chen
public class BaseController { * @version [201697]
* @see [/]
/** log4j */ * @since [/]
public static Logger log = Logger.getRootLogger(); */
public class BaseController {
/**
* <> @ExceptionHandler---- /** log4j */
* <> public static Logger log = Logger.getRootLogger();
* @param request
* @param ex /**
* @return * <> @ExceptionHandler----
* @see [##] * <>
*/ * @param request
@ExceptionHandler * @param ex
public Object exp(HttpServletRequest request, Exception ex) { * @return
* @see [##]
request.setAttribute("ex", ex); */
System.err.println("BaseController --exp "); @ExceptionHandler
// 根据不同错误转向不同页面 public Object exp(HttpServletRequest request, HttpServletResponse response,Exception ex) {
if(ex instanceof CustomException) { System.out.println("URI"+request.getRequestURI());
CustomException cuse = (CustomException) ex; request.setAttribute("ex", ex);
log.error(Configs.GLOBAL_EXP_CUSTOM); System.err.println("BaseController --exp ");
//TODO 从新封装json // 根据不同错误转向不同页面
return "{"+Configs.GLOBAL_EXP_CUSTOM+":"+cuse.getMsg()+"}"; if(ex instanceof CustomException) {
} else { CustomException cuse = (CustomException) ex;
//TODO 其他错误则 调到指定页面 Map<String, String> errmsg = new HashMap<>();
log.error(Configs.GLOBAL_EXP_NOT_CUSTOM, ex); errmsg.put("code", cuse.getCode());
return "error"; errmsg.put("msg", cuse.getMsg());
} log.error(cuse.getCode());
} response.setStatus(500);
return errmsg;
} else {
//其他错误则 调到指定页面
log.error(Configs.GLOBAL_EXP_NOT_CUSTOM, ex);
response.setStatus(500);
return "error";
}
}
} }
Loading…
Cancel
Save