Przeglądaj źródła

修改全局异常处理类

liyang 10 miesięcy temu
rodzic
commit
31aa46d1aa

+ 0 - 75
src/main/java/com/ywt/biz/common/handler/GlobalExceptionHandler.java

@@ -1,75 +0,0 @@
-package com.ywt.biz.common.handler;
-
-import com.ywt.biz.common.constant.YwtCommonRespCode;
-import com.ywt.biz.common.exception.YwtException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.RestControllerAdvice;
-
-import com.ywt.biz.common.web.YwtHttpResponse;
-
-
-/**
- * 全局异常处理器, 应用端在configuration的自定类中 集成基础类,扩展注解方法
- * @author
- */
-@RestControllerAdvice
-public class GlobalExceptionHandler {
-
-	private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
-
-	/**
-	 * error级别异常拦截
-	 * @param e
-	 * @throws
-	 * @return
-	 */
-	@ResponseBody
-	@ExceptionHandler(value = Throwable.class)
-	public YwtHttpResponse<?> txnExceptionHandler(Throwable e) {
-		logger.error("服务异常,throwable:{}",e.getMessage(),e);
-		return YwtHttpResponse.fail(YwtCommonRespCode.UNKONWN_ERR.getCode(), YwtCommonRespCode.UNKONWN_ERR.getMsg(),e.toString());
-	}
-
-	/**
-	 * 对不能单独处理的异常进行统一处理
-	 * @param e
-	 * @return
-	 */
-	@ResponseBody
-	@ExceptionHandler(value = Exception.class)
-	public YwtHttpResponse<?> txnExceptionHandler(Exception e) {
-		logger.error("服务异常,Exception:{},堆栈信息:{}",e.getMessage(),e);
-		return YwtHttpResponse.fail(YwtCommonRespCode.UNKONWN_ERR.getCode(), YwtCommonRespCode.UNKONWN_ERR.getMsg(),e.toString());
-	}
-	/**
-	 * 对不能单独处理的异常进行统一处理
-	 * @param e
-	 * @return
-	 */
-	@ResponseBody
-	@ExceptionHandler(value = RuntimeException.class)
-	public YwtHttpResponse<?> runTimeExceptionHandler(RuntimeException e) {
-		logger.error("服务异常,Exception:{}",e.getMessage(),e);
-		if (e instanceof YwtException) {
-			YwtException ae = (YwtException)e;
-			return YwtHttpResponse.fail(ae.getErrCode(), ae.getErrMsg(), ae.getErrDetail());
-		}
-		return YwtHttpResponse.fail(YwtCommonRespCode.UNKONWN_ERR.getCode(), YwtCommonRespCode.UNKONWN_ERR.getMsg(),e.toString());
-	}
-
-	/**
-	 * 对业务异常进行处理
-	 * @param e
-	 * @return
-	 */
-	@ResponseBody
-	@ExceptionHandler(value = YwtException.class)
-	public YwtHttpResponse<?> txnExceptionHandler(YwtException e){
-
-		return YwtHttpResponse.fail(e.getErrCode(),e.getErrMsg(),e.getErrDetail());
-	}
-
-}