我的lambda函数未返回错误请求

问题描述 投票:1回答:2

我正在尝试输入无效的密码,甚至在我的AWS Lambda项目中引发异常(请注意,这不是AWSless Serverless项目)。无论我做什么,状态始终为200:

这里是代码:

enter image description here

这里是API网关:

enter image description here

enter image description here

enter image description here

enter image description here

我不知道如何使此返回错误请求:(

c# amazon-web-services aws-lambda response bad-request
2个回答
0
投票

您要返回200。您需要返回NotFound()BadRequest()之类的内容。您只是返回一些(有效)json。


0
投票

所以我已经使它工作了,代码需要看起来像这样:

public APIGatewayProxyResponse TestAbcAsync(APIGatewayProxyRequest request, ILambdaContext context)
    {
        var loginRequest = JsonConvert.DeserializeObject<LoginRequest>(request.Body);
        return new APIGatewayProxyResponse
        {
            StatusCode = (int)HttpStatusCode.OK,
            Body = loginRequest.Username,
        };
    }

然后,请检查API Gateway中的设置:

enter image description here

应该选中“使用Lambda代理集成”

© www.soinside.com 2019 - 2024. All rights reserved.