我已如下配置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,但我不知道如何做?
@@ GetMapping(“ / hystrix-fallback”)公共Mono hystrixFallback(ServerWebExchange exchange){异常异常= exchange.getAttribute(ServerWebExchangeUtils.HYSTRIX_EXECUTION_EXCEPTION_ATTR);返回Mono.just(new ApiErrorResponse(“ xxxxxxxx”));}