Skip to content

Commit aac5efa

Browse files
committed
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.
1 parent ff2764f commit aac5efa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/node/routes/errors.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,16 @@ export const errorHandler: express.ErrorRequestHandler = async (err, req, res, n
6262
}
6363

6464
export const wsErrorHandler: express.ErrorRequestHandler = async (err, req, res, next) => {
65-
logger.error(`${err.message} ${err.stack}`)
6665
let statusCode = 500
6766
if (errorHasStatusCode(err)) {
6867
statusCode = err.statusCode
6968
} else if (errorHasCode(err) && notFoundCodes.includes(err.code)) {
7069
statusCode = HttpCode.NotFound
7170
}
71+
if (statusCode >= 500) {
72+
logger.error(`${err.message} ${err.stack}`)
73+
} else {
74+
logger.debug(`${err.message} ${err.stack}`)
75+
}
7276
;(req as WebsocketRequest).ws.end(`HTTP/1.1 ${statusCode} ${err.message}\r\n\r\n`)
7377
}

0 commit comments

Comments
 (0)