我们正在使用Spring Cloud Gateway与Spring Boot 2和reactive webflux模块。为其中一个路由添加了身份验证筛选器。现在,如果我们抛出一个带有特定状态代码的RuntimeException,它真的不会被拾取。早些时候这个身份验证检查是Spring中HandlerInterceptor的一部分,现在我们不能将web模块与webflux一起使用(与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内部服务器错误。这是从哪里来的?我们可以在这里从过滤器中获取错误吗?
发布于 2018-08-03 14:48:53
您可以实现一个自定义的错误处理程序,这里是spring boot document。
或者您可以简单地抛出一个ResponseStatusException,默认的错误处理程序将呈现特定的状态。
https://stackoverflow.com/questions/50480575
复制相似问题