【发布时间】:2020-06-13 01:15:23
【问题描述】:
如果用户在标头中缺少必填字段,我正在尝试发送 API 网关响应代码 401。我的 lambda 响应如下:
{
"status": "Unauthorized user",
"body": ["username"]
}
在 AWS API Gateway -> myAPI -> 资源 -> PUT 操作 -> 集成响应中,我有 2 个条目。
1。对于默认 RegEx 模式(空白)的所有成功 --> 方法响应状态为 201
2。对于正则表达式匹配,如果我使用正则表达式或在线 regex101.com 使用高于 JSON 和低于正则表达式,则存在完全匹配。
.*\"Unauthorized user\".*
<date_time in UTC> : Endpoint response body before transformations: {"status": "Unauthorized user", "body": ["username"] }
<date_time in UTC> : Execution failed due to configuration error: No match for output mapping and no default output mapping configured. Endpoint Response Status Code: 200
<date_time in UTC> : Method completed with status: 500
有人遇到过这种情况吗?如果我有 201 和空白正则表达式,我最终会得到 201...不管未经授权或内部错误或错误请求。
【问题讨论】:
-
是的;在重新阅读docs 之后,我什至尝试将正则表达式设置为 .* ,它警告说它实际上会使其成为默认响应。而且我仍然得到 200s 而不是错误代码。
标签: amazon-web-services api-gateway