首页 > 解决方案 > 当没有路由匹配时,在 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"
}

但我想发送一个自定义响应,提到标头不存在。有没有办法做到这一点?

标签: springspring-cloud-gateway

解决方案


推荐阅读