11import { Server as SocketServer } from 'socket.io' ;
22
33import Configuration from '@/core/config' ;
4- import Jrror from '@/core/error' ;
4+ import Jrror , { handleError , jssert } from '@/core/error' ;
55import Router from '@/core/router' ;
66import addMiddlewares from '@/core/router/addMiddlewares' ;
77import Server from '@/core/server' ;
@@ -87,27 +87,10 @@ class Joor {
8787 try {
8888 await this . initialize ( ) ;
8989 loadEnv ( ) ;
90- if ( ! this . configData ) {
91- throw new Jrror ( {
92- code : 'config-load-failed' ,
93- message : 'Configuration not loaded' ,
94- type : 'panic' ,
95- docsPath : '/configuration' ,
96- } ) ;
97- }
90+ jssert ( ! ! this . configData , 'Configuration not loaded' , '/configuration' , "panic" ) ;
9891 await this . server . listen ( ) ;
9992 } catch ( error : unknown ) {
100- if ( error instanceof Jrror ) {
101- error . handle ( ) ;
102- } else {
103- logger . error ( `Server start failed:` , error ) ;
104- throw new Jrror ( {
105- code : 'server-start-failed' ,
106- message : `Failed to start server: ${ error } ` ,
107- type : 'panic' ,
108- docsPath : '/joor-server' ,
109- } ) ;
110- }
93+ handleError ( error ) ;
11194 }
11295 }
11396
@@ -122,14 +105,14 @@ class Joor {
122105 this . server . server ,
123106 this . configData ?. socket ?. options
124107 ) ;
108+ jssert (
109+ ! ! this . sockets ,
110+ 'Socket.IO server not initialized' ,
111+ '/socket' ,
112+ 'error'
113+ ) ;
125114 } catch ( error ) {
126- logger . error ( 'Socket initialization failed:' , error ) ;
127- throw new Jrror ( {
128- code : 'socket-initialization-failed' ,
129- message : `Failed to initialize Socket.IO: ${ error } ` ,
130- type : 'error' ,
131- docsPath : '/websockets' ,
132- } ) ;
115+ handleError ( error ) ;
133116 }
134117 }
135118
0 commit comments