我们正在使用Spring Boot 2和reactive WebFlux模块的Spring Cloud Gateway。
其中一个路由添加了认证过滤器。现在,如果我们抛出一个具有特定状态码的RuntimeException,它实际上无法被捕获。
之前这个认证检查是Spring中的HandlerInterceptor的一部分,但是现在我们不能与WebFlux一起使用web模块(来自Spring cloud gateway的冲突)。
示例:
其中一个路由添加了认证过滤器。现在,如果我们抛出一个具有特定状态码的RuntimeException,它实际上无法被捕获。
之前这个认证检查是Spring中的HandlerInterceptor的一部分,但是现在我们不能与WebFlux一起使用web模块(来自Spring cloud gateway的冲突)。
示例:
@Override
public GatewayFilter apply(Object config) {
ServerHttpRequest httpRequest = exchange.getRequest();
if(!someUtil.validRequest(httpRequest) {
throw new RuntimeException("Throw 401 Unauthorized with Custom error code and message");
}
}
目前,实际响应始终会给出一个500内部服务器错误。这是从何处发出的?我们能否在这里获取来自过滤器的错误信息?
ResponseStatusException
对我来说是有效的,但它仍然绕过了 Spring Boot 的@ControllerAdvice
控制器。 - Tim Biegeleisen