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 a21676b34bbfbebd367c2e8b5bd5a2f8dc94fcec..4874e548dc48cc8f337c29fa65d7ee5772dfde8e 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()); } /**