File tree Expand file tree Collapse file tree 1 file changed +15
-9
lines changed
Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -17,15 +17,21 @@ interface Logger {
1717export function createHttpHandler ( roomManager : IRoomManager , logger : Logger ) {
1818 return async ( req : IncomingMessage , res : ServerResponse ) => {
1919 if ( req . method === 'GET' && req . url === '/health' ) {
20- const connections = await roomManager . getTotalActiveConnections ( )
21- res . writeHead ( 200 , { 'Content-Type' : 'application/json' } )
22- res . end (
23- JSON . stringify ( {
24- status : 'ok' ,
25- timestamp : new Date ( ) . toISOString ( ) ,
26- connections,
27- } )
28- )
20+ try {
21+ const connections = await roomManager . getTotalActiveConnections ( )
22+ res . writeHead ( 200 , { 'Content-Type' : 'application/json' } )
23+ res . end (
24+ JSON . stringify ( {
25+ status : 'ok' ,
26+ timestamp : new Date ( ) . toISOString ( ) ,
27+ connections,
28+ } )
29+ )
30+ } catch ( error ) {
31+ logger . error ( 'Error in health check:' , error )
32+ res . writeHead ( 503 , { 'Content-Type' : 'application/json' } )
33+ res . end ( JSON . stringify ( { status : 'error' , message : 'Health check failed' } ) )
34+ }
2935 return
3036 }
3137
You can’t perform that action at this time.
0 commit comments