Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ws-response: Invalid request.response given to API Gateway #1219

Closed
nbusser opened this issue Jun 19, 2024 · 1 comment
Closed

ws-response: Invalid request.response given to API Gateway #1219

nbusser opened this issue Jun 19, 2024 · 1 comment
Labels

Comments

@nbusser
Copy link

nbusser commented Jun 19, 2024

Description

At the end of ws-response middleware, we set request.response.statusCode to 200, so API Gateway knows that everything went well.

However, it actually wants an object containing ONLY statusCode. Otherwise, it will send an Internal Error message to the client.

Example:

In my lambda:

const handler = () => {
     return {
         Data: 'Hello',
    };
}

Here is the content of request.response at the end of the middleware:
{ ConnectionId: 'ZmDx-dJ4FiACFkQ=', Data: '"Hello"', statusCode: 200 }

I receive the following error message on the client:

Message from the server: "Hello"
Message from the server: {"message": "Internal server error", "connectionId":"ZmDx-dJ4FiACFkQ=", "requestId":"ZmDyDGyFliAFhVQ="}

Fix:

Replace line 42 by:

request.response = {
    statusCode: 200
}

By doing this, with the same lambda code, I receive the following message on the client:

Message from the server: "Hello"

Environment:

  • Node.js: 20
  • Middy: 4.x
  • AWS SDK 3.x
@nbusser nbusser added the bug label Jun 19, 2024
@willfarrell
Copy link
Member

willfarrell commented Jun 22, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants