我们将 Spring Cloud Gateway 与 Spring Boot 2 和响应式 webflux 模块一起使用。有一个为其中一条路由添加的身份验证过滤器。现在,如果我们抛出一个带有特定状态码的 RuntimeException,它实际上并没有启动。之前这个 auth 检查是 Spring 中 HandlerInterceptor 的一部分,现在我们不能将 web 模块与 webflux 一起使用(来自 Spring 云网关的冲突)。前任:
@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 内部服务器错误。这是从哪里来的?我们可以在这里从过滤器中获取错误吗?