From b367bf1c31cf63e9122f08164bf70f2bc109f83d Mon Sep 17 00:00:00 2001 From: guo <1716967236@qq.com> Date: Sun, 22 Sep 2024 08:10:12 +0800 Subject: [PATCH] =?UTF-8?q?[xingyu.guo]=20feat:=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9=E5=85=A8=E9=83=A8=E5=BC=82=E5=B8=B8=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/GlobalExceptionHandler.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/guo/learningprogresstracker/common/GlobalExceptionHandler.java b/src/main/java/com/guo/learningprogresstracker/common/GlobalExceptionHandler.java index b267597..2a4ca01 100644 --- a/src/main/java/com/guo/learningprogresstracker/common/GlobalExceptionHandler.java +++ b/src/main/java/com/guo/learningprogresstracker/common/GlobalExceptionHandler.java @@ -1,22 +1,22 @@ package com.guo.learningprogresstracker.common; - + import com.guo.learningprogresstracker.entity.CommonResult; import com.guo.learningprogresstracker.exception.AppException; import com.guo.learningprogresstracker.exception.ErrorParameterException; import com.guo.learningprogresstracker.exception.NotFindEntitiesException; +import lombok.extern.slf4j.Slf4j; import org.springframework.validation.BindingResult; -import org.springframework.web.bind.MethodArgumentNotValidException; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.bind.annotation.RestControllerAdvice; -import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; /** * @author guo */ @ControllerAdvice +@Slf4j public class GlobalExceptionHandler { @ExceptionHandler({ErrorParameterException.class}) @@ -48,4 +48,12 @@ public class GlobalExceptionHandler { return CommonResult.error(bindingResult.getFieldError().getDefaultMessage()); } + @ExceptionHandler(Exception.class) + @ResponseBody + public CommonResult Exception(Exception ex){ + log.error("系统异常",ex); + //code:400 + return CommonResult.error(ex.getMessage()); + } + } \ No newline at end of file