首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Cloud Gateway Filters抛出自定义运行时异常

Spring Cloud Gateway Filters抛出自定义运行时异常
EN

Stack Overflow用户
提问于 2018-05-23 13:39:52
回答 1查看 5.1K关注 0票数 5

我们正在使用Spring Cloud Gateway与Spring Boot 2和reactive webflux模块。为其中一个路由添加了身份验证筛选器。现在,如果我们抛出一个带有特定状态代码的RuntimeException,它真的不会被拾取。早些时候这个身份验证检查是Spring中HandlerInterceptor的一部分,现在我们不能将web模块与webflux一起使用(与Spring cloud gateway冲突)。例如:

代码语言:javascript
复制
@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内部服务器错误。这是从哪里来的?我们可以在这里从过滤器中获取错误吗?

EN

回答 1

Stack Overflow用户

发布于 2018-08-03 14:48:53

您可以实现一个自定义的错误处理程序,这里是spring boot document

或者您可以简单地抛出一个ResponseStatusException,默认的错误处理程序将呈现特定的状态。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50480575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档