From b1eb2b78af09d2a4a4fbf3c40d9c4e686573213a Mon Sep 17 00:00:00 2001 From: taoxin Date: Sat, 24 Jan 2026 20:42:55 +0800 Subject: [PATCH 1/2] fix: enhance WebSocket error handling with status code logging --- src/node/routes/errors.ts | 3 +++ 1 file changed, 3 insertions(+) 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`) } From 6f601e970b9a19e9221c7fd1dce559f1cad8983b Mon Sep 17 00:00:00 2001 From: taoxin Date: Tue, 27 Jan 2026 09:05:14 +0800 Subject: [PATCH 2/2] feat: add final error handlers for HTTP and WebSocket with detailed documentation --- src/node/routes/errors.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/node/routes/errors.ts b/src/node/routes/errors.ts index 6a297e5fb5dd..c1439d6adedc 100644 --- a/src/node/routes/errors.ts +++ b/src/node/routes/errors.ts @@ -28,6 +28,12 @@ export const errorHasCode = (error: any): error is ErrorWithCode => { const notFoundCodes = [404, "ENOENT", "EISDIR"] +/** + * Final HTTP error handler. + * + * Note: This handler intentionally does not call `next()` even though it + * accepts it as an argument; it is expected to be mounted last. + */ export const errorHandler: express.ErrorRequestHandler = async (err, req, res, next) => { let statusCode = 500 @@ -61,6 +67,12 @@ export const errorHandler: express.ErrorRequestHandler = async (err, req, res, n } } +/** + * Final WebSocket error handler. + * + * Note: This handler intentionally does not call `next()` even though it + * accepts it as an argument; it is expected to be mounted last. + */ export const wsErrorHandler: express.ErrorRequestHandler = async (err, req, res, next) => { let statusCode = 500 if (errorHasStatusCode(err)) { @@ -73,8 +85,5 @@ 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`) }