From eedf241f456c3bee30e2cbe746c38c381420be1a Mon Sep 17 00:00:00 2001 From: itao Date: Sun, 7 Jan 2024 21:40:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=A8=E5=B1=80=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=8D=95=E8=8E=B7BizException=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tag/controller/BaseExceptionHandler.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/luoo_tag/src/main/java/com/luoo/tag/controller/BaseExceptionHandler.java b/luoo_tag/src/main/java/com/luoo/tag/controller/BaseExceptionHandler.java index 9ed0ff9..e0e0ebb 100644 --- a/luoo_tag/src/main/java/com/luoo/tag/controller/BaseExceptionHandler.java +++ b/luoo_tag/src/main/java/com/luoo/tag/controller/BaseExceptionHandler.java @@ -1,22 +1,30 @@ package com.luoo.tag.controller; + +import com.luoo.common.exception.BizException; import entity.Result; import entity.StatusCode; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; /** * 统一异常处理类 */ +@Slf4j @ControllerAdvice public class BaseExceptionHandler { @ExceptionHandler(value = Exception.class) @ResponseBody public Result error(Exception e){ - e.printStackTrace(); + log.error("执行出错", e); return new Result(false, StatusCode.ERROR, "执行出错"); } + + @ExceptionHandler(value = BizException.class) + @ResponseBody + public Result error(BizException e){ + log.info("业务错误", e); + return new Result(false, StatusCode.ERROR, "业务错误"); + } }