diff --git a/src/node/routes/errors.ts b/src/node/routes/errors.ts index da0ee8d7c07f..6a297e5fb5dd 100644 --- a/src/node/routes/errors.ts +++ b/src/node/routes/errors.ts @@ -73,5 +73,8 @@ export const wsErrorHandler: express.ErrorRequestHandler = async (err, req, res, } else { logger.debug(`${err.message} ${err.stack}`) } + // Close the WebSocket connection with the appropriate HTTP status code. + // We don't call next() here because the error has been fully handled: + // the connection is closed and the error has been logged. ;(req as WebsocketRequest).ws.end(`HTTP/1.1 ${statusCode} ${err.message}\r\n\r\n`) }