mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2024-12-23 05:00:25 +08:00
fix(GlobalExceptionHandler.class): 微服务Feign调用全局异常处理
This commit is contained in:
parent
20ee7edd63
commit
e4f81463d8
@ -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 <T> Result<T> 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 <T> Result<T> processException(FeignException.BadRequest e) {
|
||||
log.info("微服务feign调用异常:{}", e.getMessage());
|
||||
return Result.failed(e.getMessage());
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(BizException.class)
|
||||
public <T> Result<T> handleBizException(BizException e) {
|
||||
@ -185,8 +190,7 @@ public class GlobalExceptionHandler {
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(Exception.class)
|
||||
public <T> Result<T> handleException(Exception e) {
|
||||
log.error("未知异常,异常原因:{}", e.getMessage(), e);
|
||||
return Result.failed();
|
||||
return Result.failed(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user