diff --git a/apps/sim/socket/routes/http.ts b/apps/sim/socket/routes/http.ts index 67753aa2f..0d57ff29f 100644 --- a/apps/sim/socket/routes/http.ts +++ b/apps/sim/socket/routes/http.ts @@ -17,15 +17,21 @@ interface Logger { export function createHttpHandler(roomManager: IRoomManager, logger: Logger) { return async (req: IncomingMessage, res: ServerResponse) => { if (req.method === 'GET' && req.url === '/health') { - const connections = await roomManager.getTotalActiveConnections() - res.writeHead(200, { 'Content-Type': 'application/json' }) - res.end( - JSON.stringify({ - status: 'ok', - timestamp: new Date().toISOString(), - connections, - }) - ) + try { + const connections = await roomManager.getTotalActiveConnections() + res.writeHead(200, { 'Content-Type': 'application/json' }) + res.end( + JSON.stringify({ + status: 'ok', + timestamp: new Date().toISOString(), + connections, + }) + ) + } catch (error) { + logger.error('Error in health check:', error) + res.writeHead(503, { 'Content-Type': 'application/json' }) + res.end(JSON.stringify({ status: 'error', message: 'Health check failed' })) + } return }