如果我的 Lambda 抛出消息 404
的 Exception
,那么在 API Gateway 中看到的响应是
{
"errorMessage":"404",
"errorType":"java.lang.Exception",
"stackTrace":[..."]
}
我可以匹配 errorMessage 来影响 HTTP 结果。
但是,如果我有效地返回相同的结果,即:
{
"errorMessage":"404",
"errorType":"Error"
}
API Gateway 似乎没有识别出错误并始终返回 200。
有什么方法可以让我漂亮的功能代码在不抛出异常的情况下发出错误信号?
最佳答案
The Lambda function must exit with an error in order for the response pattern to be evaluated – it is not possible to “fake” an error response by simply returning an “errorMessage” field in a successful Lambda response.
https://aws.amazon.com/blogs/compute/error-handling-patterns-in-amazon-api-gateway-and-aws-lambda/
关于java - 有什么方法可以在不抛出异常的情况下在 AWS Lambda for Java 中发出错误信号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45108530/