Fix/more logging (#34)

* A tiny bit clearer logging

* Enhance WebSocket close event logging to include closure code and reason
This commit is contained in:
Adam Shiervani 2025-04-09 17:00:44 +02:00 committed by GitHub
parent 710c4d73b4
commit efce3ebe7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -172,16 +172,18 @@ function setupDeviceWebSocket(deviceWs: WebSocket, device: Device, req: Incoming
await cleanup();
});
deviceWs.on("close", async () => {
console.log(`[Device] Connection closed for ${id}`);
deviceWs.on("close", async (code, reason) => {
console.log(
`[Device] Connection closed for ${id} with code ${code} and reason ${reason}`,
);
await cleanup();
});
// Cleanup function
async function cleanup() {
console.log(`[Device] Cleanup for ${id}`);
activeConnections.delete(id);
clearInterval(checkAliveInterval);
console.log(`[Device] Cleanup for ${id}`);
await updateDeviceLastSeen(id);
}
}