From aac5efa046f73ef231b7742110abc1d8a44a4d63 Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 1 May 2023 10:41:10 -0800 Subject: [PATCH] Do not log < 500 on web sockets as errors For example if someone spams a web socket without authentication we should not log "forbidden". Forbidden is normal/expected operation, not an error. --- src/node/routes/errors.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/node/routes/errors.ts b/src/node/routes/errors.ts index 712bba604..743699c84 100644 --- a/src/node/routes/errors.ts +++ b/src/node/routes/errors.ts @@ -62,12 +62,16 @@ 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}`) let statusCode = 500 if (errorHasStatusCode(err)) { statusCode = err.statusCode } else if (errorHasCode(err) && notFoundCodes.includes(err.code)) { statusCode = HttpCode.NotFound } + if (statusCode >= 500) { + logger.error(`${err.message} ${err.stack}`) + } else { + logger.debug(`${err.message} ${err.stack}`) + } ;(req as WebsocketRequest).ws.end(`HTTP/1.1 ${statusCode} ${err.message}\r\n\r\n`) }