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,但我不知道该怎么做?

4

1 回答 1

-1

@GetMapping("/hystrix-fallback") public Mono hystrixFallback(ServerWebExchange exchange) { Exception exception = exchange.getAttribute(ServerWebExchangeUtils.HYSTRIX_EXECUTION_EXCEPTION_ATTR); return Mono.just(new ApiErrorResponse("xxxxxxxx")); }

于 2020-04-24T06:01:07.977 回答