aws / chalice

Python Serverless Microframework for AWS
Apache License 2.0
10.67k stars 1.01k forks source link

websocket close connection with error code #2060

Open naomiven opened 1 year ago

naomiven commented 1 year ago

in WebsocketAPI can we have a method that closes a websocket connection with a specified code?

similar to this

according to the websocket protocol we should be able to do this -> spec

right now, in API gateway logs, the connection is always closed with status code 1000 when calling the existing close method:

app.websocket_api.close(event.connection_id)

API gateway logs:

Endpoint request body after transformations: 
...
        {
          "routeKey": "$disconnect",
          "disconnectStatusCode": 1000,
          "authorizer": {
              "principalId": "user"
        },
        "eventType": "DISCONNECT",
        "requestTime": "20/Jul/2023:23:29:25 +0000",
        "messageDirection": "IN",
        "disconnectReason": "Connection Closed Normally",
        "connectedAt": 1689895754759,
        "requestTimeEpoch": 1689895765983,
...