spring - 当没有路由匹配时,在 Spring Cloud Gateway 中发送自定义错误响应
问题描述
在 Spring Cloud Gateway 中,我想发送自定义错误以防特定谓词匹配失败。例如:- 我有一个路径和一个标题谓词。像这样的东西-
- id: test
uri: http://localhost:8000/
predicates:
- Path=/consignment
- Header=h,h1
因此,如果路径数学和标头没有,则请求将失败并出现未找到错误,例如默认情况下 -
{
"timestamp": "2020-03-08T20:05:42.440+0000",
"path": "/test",
"status": 404,
"error": "Not Found",
"message": null,
"requestId": "6dd2e799"
}
但我想发送一个自定义响应,提到标头不存在。有没有办法做到这一点?
解决方案
推荐阅读
- python - Python pandas对字母数字进行排序
- python - pd.concat 是在循环中组合这两个数据帧的正确函数吗?
- r - R,条件累积和到最大值
- c# - C#和正确的继承方式
- java - 在使用 SAST 工具时,为什么我们必须为编译语言(例如 C/C++)使用“构建包装器”?
- c++ - 为什么我们不能将数组的地址分配给指针?
- r - 如何从线性图中对聚类进行分类
- makefile - 从源代码构建 mysql-workbench 时无法访问 jarfile ANTLR_JAR_PATH-NOTFOUND
- javascript - 明确此 JavaScript 语法
- python - 如何获得过程的返回值