Skip to content

Commit

Permalink
Fix web sockets not closing with error code
Browse files Browse the repository at this point in the history
  • Loading branch information
code-asher committed Mar 3, 2023
1 parent 9f64d93 commit ffde71a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/node/routes/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,11 @@ export const errorHandler: express.ErrorRequestHandler = async (err, req, res, n

export const wsErrorHandler: express.ErrorRequestHandler = async (err, req, res, next) => {
logger.error(`${err.message} ${err.stack}`)
;(req as WebsocketRequest).ws.end()
let statusCode = 500
if (errorHasStatusCode(err)) {
statusCode = err.statusCode
} else if (errorHasCode(err) && notFoundCodes.includes(err.code)) {
statusCode = HttpCode.NotFound
}
;(req as WebsocketRequest).ws.end(`HTTP/1.1 ${statusCode} ${err.message}\r\n\r\n`)
}

0 comments on commit ffde71a

Please sign in to comment.