Skip to content

Commit 42cce7c

Browse files
committed
fix: Fixed some methods of joor class
1 parent 284bbaa commit 42cce7c

2 files changed

Lines changed: 11 additions & 27 deletions

File tree

src/core/joor.ts

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Server as SocketServer } from 'socket.io';
22

33
import Configuration from '@/core/config';
4-
import Jrror from '@/core/error';
4+
import Jrror, { handleError, jssert } from '@/core/error';
55
import Router from '@/core/router';
66
import addMiddlewares from '@/core/router/addMiddlewares';
77
import 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

src/core/tt.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from '@/types/response';
1616
const response = ServerResponse.prototype;
1717
response.status = function (this: ServerResponse, status: RESPONSE_STATUS) {
18+
1819
try {
1920
if (!Number.isInteger(status)) {
2021
throw new Jrror({

0 commit comments

Comments
 (0)