qa-prevention-gwj/src/main/java/com/zcloud/util/examUntil/GlobalExceptionHandler.java

95 lines
2.8 KiB
Java
Raw Normal View History

2024-01-17 13:54:06 +08:00
package com.zcloud.util.examUntil;
/**
* TODO
* wangxuan
* www.zcloudchina.com
*/
import com.zcloud.util.ReturnMap;
import org.mybatis.spring.MyBatisSystemException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import static com.zcloud.util.examUntil.CodeMessageEnum.SERVER_BUSY;
/**
*
*/
@RestControllerAdvice(annotations = {ErrorOperation.class})
//@Slf4j
public class GlobalExceptionHandler {
/**
*
*
*/
@ExceptionHandler(value = BizException.class)
@ResponseBody
public ReturnMap bizExceptionHandler(HttpServletRequest req, BizException e) {
e.printStackTrace();
// log.error("发生业务异常: {}, 请求接口: {}", e.getMessage(), req.getRequestURI());
return ReturnMap.error("2001" ,e.getMessage(), req.getRequestURI());
}
/**
*
*
* @param e
* @param req
*/
@ExceptionHandler(value = NullPointerException.class)
@ResponseBody
public ReturnMap exceptionHandler(HttpServletRequest req, NullPointerException e) {
e.printStackTrace();
// log.error("空指针异常信息: {}, 请求接口: {}", e, req.getRequestURI());
return ReturnMap.error(SERVER_BUSY, req.getRequestURI());
}
/**
*
*
*/
@ExceptionHandler(value = HttpRequestMethodNotSupportedException.class)
@ResponseBody
public ReturnMap methodNotSupportedExceptionHandler(HttpServletRequest req, Exception e) {
e.printStackTrace();
// log.error("请求方法异常信息: {},请求接口: {}", e, req.getRequestURI());
return ReturnMap.error(SERVER_BUSY, req.getRequestURI());
}
/**
* SQL
*/
@ExceptionHandler(value = MyBatisSystemException.class)
@ResponseBody
public ReturnMap sqlSyntaxErrorExceptionHandler(HttpServletRequest req, Exception e) {
e.printStackTrace();
// log.error("MyBatis系统异常信息: {},请求接口: {}", e, req.getRequestURI());
return ReturnMap.error(SERVER_BUSY, req.getRequestURI());
}
/**
*
*
* @param req
* @param e
*/
@ExceptionHandler(value = Exception.class)
@ResponseBody
public ReturnMap exceptionHandler(HttpServletRequest req, Exception e) {
e.printStackTrace();
// log.error("未知异常: {}, 请求接口: {}", e, req.getRequestURI());
return ReturnMap.error(SERVER_BUSY, req.getRequestURI());
}
}