MilkTea027
MilkTea027

Reputation: 301

My lambda function is not returning bad request

I am trying to enter an invalid password, or even throw an exception in my AWS Lambda project (note that this is not an AWS Serverless project). No matter what I do, the status is always 200:

Here is code:

enter image description here

Here is API Gateway:

enter image description here

enter image description here

enter image description here

enter image description here

I have no other idea how to make this return bad request :(

Upvotes: 0

Views: 978

Answers (2)

MilkTea027
MilkTea027

Reputation: 301

So I already made it work, what the code needs to look like is something like this:

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

Then the setup in API Gateway needs to have this checked:

enter image description here

The "Use Lambda Proxy Integration" should be checked

Upvotes: 1

Neil
Neil

Reputation: 11889

You ARE returning a 200. You need to return something like NotFound() or BadRequest(). You are just returning some (valid) json.

Upvotes: 0

Related Questions