带有hystrix后备的spring-cloud-gateway,如何获取异常详细信息?

问题描述 投票:1回答:1

我已如下配置Spring Cloud Gateway的hystrix:

default-filters:
-   name: Hystrix
    args:
        name: defaultGatewayCommand
        fallbackUri: forward:/hystrix-fallback

例如,当我在项目中引发ResponseStatusException异常时,将触发hystrix后备。

@GetMapping("/hystrix-fallback")
public Mono<ApiErrorResponse> hystrixFallback() {
    return Mono.just(new ApiErrorResponse("xxxxxxxx"));
}

我想捕获一些错误信息并构建新的ApiErrorResponse,但我不知道如何做?

spring-cloud spring-cloud-gateway
1个回答
0
投票

@@ GetMapping(“ / hystrix-fallback”)公共Mono hystrixFallback(ServerWebExchange exchange){异常异常= exchange.getAttribute(ServerWebExchangeUtils.HYSTRIX_EXECUTION_EXCEPTION_ATTR);返回Mono.just(new ApiErrorResponse(“ xxxxxxxx”));}

© www.soinside.com 2019 - 2024. All rights reserved.