From e4f81463d833edfeb60a7281c6dfe2e5d937f031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=89=E6=9D=A5=E6=8A=80=E6=9C=AF?= <1490493387@qq.com> Date: Wed, 20 Oct 2021 00:26:56 +0800 Subject: [PATCH] =?UTF-8?q?fix(GlobalExceptionHandler.class):=20=E5=BE=AE?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1Feign=E8=B0=83=E7=94=A8=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/exception/GlobalExceptionHandler.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java index a21676b34..4874e548d 100644 --- a/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java +++ b/youlai-common/common-web/src/main/java/com/youlai/common/web/exception/GlobalExceptionHandler.java @@ -4,6 +4,7 @@ import cn.hutool.json.JSONObject; import com.fasterxml.jackson.core.JsonProcessingException; import com.youlai.common.result.Result; import com.youlai.common.result.ResultCode; +import feign.FeignException; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.TypeMismatchException; import org.springframework.http.HttpStatus; @@ -159,19 +160,23 @@ public class GlobalExceptionHandler { return Result.failed(e.getMessage()); } - /** - * CompletionException - */ + @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(CompletionException.class) public Result processException(CompletionException e) { - log.error(e.getMessage(), e); if (e.getMessage().startsWith("feign.FeignException")) { return Result.failed("微服务调用异常"); } return handleException(e); } + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(FeignException.BadRequest.class) + public Result processException(FeignException.BadRequest e) { + log.info("微服务feign调用异常:{}", e.getMessage()); + return Result.failed(e.getMessage()); + } + @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(BizException.class) public Result handleBizException(BizException e) { @@ -185,8 +190,7 @@ public class GlobalExceptionHandler { @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(Exception.class) public Result handleException(Exception e) { - log.error("未知异常,异常原因:{}", e.getMessage(), e); - return Result.failed(); + return Result.failed(e.getLocalizedMessage()); } /**