1
votes

I am using aws lambda proxy integration.

I hit the API in response if Success means 200 response is coming if error means 500 error is coming correct.

        {
    try:
          return {
                "statusCode": str(200),
                "body": json.dumps("Hello"),
                "headers": headers,
            }

    except Exception as e:
         return {
                "statusCode": str(500),
                "body": json.dumps("Error"),
                "headers": headers,
            }

}

But when I am trying to return the exception from another method inside the lambda in a postman error response is coming, but statuscode is 200 response is there. Below is the code.

    def getMethod(val):
   try:
        a= val
        return {
            "statusCode": str(200),
            "body": json.dumps("Success"),
            "headers": headers,
        }
    except Exception as e:
         return {
            "statusCode": str(500),
            "body": json.dumps("Error in getMethod"),
            "headers": headers,
        }

handler request(event,context):
    try:
      response = getMethod(
      return {
            "statusCode": str(200),
            "body": json.dumps(response),
            "headers": headers,
        }

    except Exception as e:
      return {
            "statusCode": str(500),
            "body": json.dumps("Error"),
            "headers": headers,
        }
1
can you show your gateway config, might be related to something theredege

1 Answers

0
votes

I am sorry I didn't understand your code. You have called the "getMethod" with a return value :

return { "statusCode": str(200), "body": json.dumps(response), "headers": headers, }

in which you have specified "response" which is the return value of getMethod. Most probably you're getting the 200 response because the getMethod is evaluating to return the try part and not the except part.