More verbose websocket error logs

This commit is contained in:
Mononaut 2023-11-25 09:02:27 +00:00
parent 0f04f751e1
commit 652100f774
No known key found for this signature in database
GPG Key ID: A3F058E41374C04E

View File

@ -94,10 +94,11 @@ class WebsocketHandler {
throw new Error('WebSocket.Server is not set');
}
this.wss.on('connection', (client: WebSocket) => {
this.wss.on('connection', (client: WebSocket, req) => {
this.numConnected++;
client['remoteAddress'] = req.headers['x-forwarded-for'] || req.socket?.remoteAddress || 'unknown';
client.on('error', (e) => {
logger.info('websocket client error: ' + (e instanceof Error ? e.message : e));
logger.info(`websocket client error from ${client['remoteAddress']}: ` + (e instanceof Error ? e.message : e));
client.close();
});
client.on('close', () => {
@ -285,7 +286,7 @@ class WebsocketHandler {
client.send(serializedResponse);
}
} catch (e) {
logger.debug('Error parsing websocket message: ' + (e instanceof Error ? e.message : e));
logger.debug(`Error parsing websocket message from ${client['remoteAddress']}: ` + (e instanceof Error ? e.message : e));
client.close();
}
});