2 changed files with 1 additions and 62 deletions
@ -1,61 +0,0 @@ |
|||||
package cn.chjyj.szwh.controller; |
|
||||
|
|
||||
import cn.chjyj.szwh.exception.ChException; |
|
||||
import com.alibaba.fastjson.JSONObject; |
|
||||
import org.apache.commons.logging.Log; |
|
||||
import org.apache.commons.logging.LogFactory; |
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice; |
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler; |
|
||||
import org.springframework.web.bind.annotation.ResponseBody; |
|
||||
|
|
||||
/** |
|
||||
* 全局异常控制器 |
|
||||
*/ |
|
||||
@ControllerAdvice |
|
||||
public class GlobalErrorController { |
|
||||
//日志初始化
|
|
||||
private static final Log log = LogFactory.getLog(GlobalErrorController.class); |
|
||||
|
|
||||
private JSONObject jsonObject=new JSONObject(); |
|
||||
/** |
|
||||
* 异常信息输出 |
|
||||
* @return |
|
||||
*/ |
|
||||
@ExceptionHandler(ChException.class) |
|
||||
@ResponseBody |
|
||||
public JSONObject aisHandler(ChException ex){ |
|
||||
log.error("Exception:"+ex); |
|
||||
jsonObject.put("code",500); |
|
||||
jsonObject.put("msg",ex.getMsg()); |
|
||||
return jsonObject; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 空指针异常 |
|
||||
* @param e |
|
||||
* @return |
|
||||
*/ |
|
||||
@ExceptionHandler(value =NullPointerException.class) |
|
||||
@ResponseBody |
|
||||
public JSONObject exceptionHandler(NullPointerException e){ |
|
||||
log.error("空指针异常:"+e); |
|
||||
String msg = e.getMessage()==null?"module not found!":e.getMessage(); |
|
||||
jsonObject.put("code",500); |
|
||||
jsonObject.put("msg",msg); |
|
||||
return jsonObject; |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* 常规异常信息 |
|
||||
* @param ex |
|
||||
* @return |
|
||||
*/ |
|
||||
@ExceptionHandler(value = Exception.class) |
|
||||
@ResponseBody |
|
||||
public JSONObject exceptionHandler(Exception ex){ |
|
||||
log.error("异常信息:"+ex); |
|
||||
jsonObject.put("code",500); |
|
||||
jsonObject.put("msg",ex.getMessage()); |
|
||||
return jsonObject; |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue