全局异常exp方法修改

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

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

Loading…
Cancel
Save