opticore-webapp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/index.cjs +1080 -0
  2. package/dist/index.d.cts +408 -0
  3. package/dist/index.d.ts +408 -0
  4. package/dist/index.js +1038 -0
  5. package/package.json +46 -0
  6. package/src/application/exceptions/messages.exception.ts +67 -0
  7. package/src/application/http/response.http.ts +67 -0
  8. package/src/application/service/core.service.ts +180 -0
  9. package/src/core/config/.gitkeep +0 -0
  10. package/src/core/errors/.gitkeep +0 -0
  11. package/src/core/events/errors/serverListen.event.error.ts +421 -0
  12. package/src/core/events/requestCalls.event.ts +86 -0
  13. package/src/core/handlers/errors/base/stackTraceError.ts +23 -0
  14. package/src/core/handlers/errors/stackTraceAssertionError.ts +13 -0
  15. package/src/core/handlers/errors/stackTraceEvalError.ts +12 -0
  16. package/src/core/handlers/errors/stackTraceGeneralError.ts +13 -0
  17. package/src/core/handlers/errors/stackTraceOpenSSLError.ts +12 -0
  18. package/src/core/handlers/errors/stackTraceRangeError.ts +12 -0
  19. package/src/core/handlers/errors/stackTraceReferenceError.ts +13 -0
  20. package/src/core/handlers/errors/stackTraceSyntaxError.ts +12 -0
  21. package/src/core/handlers/errors/stackTraceSystemError.ts +14 -0
  22. package/src/core/handlers/errors/stackTraceTypeError.ts +13 -0
  23. package/src/core/handlers/errors/stackTraceURIError.ts +13 -0
  24. package/src/core/handlers/eventProcess.handler.ts +106 -0
  25. package/src/core/utils/dateTimeFormatted.utils.ts +6 -0
  26. package/src/core/utils/logMessage.utils.ts +20 -0
  27. package/src/core/utils/modulesLoaded.utils.ts +16 -0
  28. package/src/core/webServer.core.ts +110 -0
  29. package/src/domains/constants/errorName.constant.ts +12 -0
  30. package/src/domains/constants/event.constant.ts +15 -0
  31. package/src/domains/constants/eventNameError.constant.ts +8 -0
  32. package/src/domains/constants/httpStatusCodes.constant.ts +375 -0
  33. package/src/domains/constants/logLevel.constant.ts +6 -0
  34. package/src/domains/env/access.env.ts +23 -0
  35. package/src/domains/interfaces/envVariables.interface.ts +16 -0
  36. package/src/domains/interfaces/kernelModule.interface.ts +6 -0
  37. package/src/domains/interfaces/routeDefinition.interface.ts +6 -0
  38. package/src/domains/types/kernelModule.type.ts +3 -0
  39. package/src/index.ts +20 -0
  40. package/src/infrastructure/events/.gitkeep +0 -0
  41. package/src/infrastructure/handlers/.gitkeep +0 -0
  42. package/src/presentation/middleware/.gitkeep +0 -0
  43. package/tsconfig.json +26 -0
  44. package/tsup.config.ts +11 -0
@@ -0,0 +1,421 @@
1
+ import process from "process";
2
+ import colors from "ansi-colors";
3
+ import express from "express";
4
+ import chalk from "chalk";
5
+ import StackTraceError from "@webApp/core/handlers/errors/base/stackTraceError";
6
+ import {HttpStatusCodesConstant as status} from "@webApp/domains/constants/httpStatusCodes.constant";
7
+ import {LogMessageUtils} from "@webApp/core/utils/logMessage.utils";
8
+ import {dateTimeFormattedUtils as currentDate} from "@webApp/core/utils/dateTimeFormatted.utils";
9
+ import {messageException as msg} from "@webApp/application/exceptions/messages.exception";
10
+ import {CEventNameError as eventName} from "@webApp/domains/constants/eventNameError.constant";
11
+
12
+
13
+ export class ServerListenEventError {
14
+ static hostPortUndefined(): void {
15
+ const stackTrace: StackTraceError = this.traceError(msg.errorHostUrl, msg.listening, status.BAD_REQUEST);
16
+ LogMessageUtils.error(
17
+ msg.webServer,
18
+ msg.badHost,
19
+ stackTrace.stack!,
20
+ msg.errorHostUrl,
21
+ status.BAD_REQUEST
22
+ );
23
+ process.exit();
24
+ }
25
+ static hostUndefined(): void {
26
+ const stackTrace: StackTraceError = this.traceError(msg.badHost, msg.listening, status.BAD_REQUEST);
27
+ LogMessageUtils.error(
28
+ msg.webServer,
29
+ msg.badHost,
30
+ stackTrace.stack!,
31
+ msg.errorHost,
32
+ status.BAD_REQUEST
33
+ );
34
+ process.exit();
35
+ }
36
+ static portUndefined(): void {
37
+ const stackTrace: StackTraceError = this.traceError(msg.badPort, msg.listening, status.BAD_REQUEST);
38
+ LogMessageUtils.error(
39
+ msg.webServer,
40
+ msg.badPort,
41
+ stackTrace.stack!,
42
+ msg.errorPort,
43
+ status.BAD_REQUEST
44
+ );
45
+ process.exit();
46
+ }
47
+ static onEventError(err: Error): void {
48
+ LogMessageUtils.error(
49
+ "Server start error",
50
+ "Error",
51
+ err.stack,
52
+ err.message,
53
+ status.SERVICE_UNAVAILABLE
54
+ );
55
+ }
56
+ static listenerError(error: Error): void {
57
+ const stackTrace: StackTraceError = this.traceError(
58
+ error.message,
59
+ error.name,
60
+ status.BAD_REQUEST
61
+ );
62
+
63
+ LogMessageUtils.error(
64
+ "Event error",
65
+ "Error",
66
+ error.stack!,
67
+ stackTrace.message,
68
+ status.SERVICE_UNAVAILABLE
69
+ );
70
+ }
71
+ static processBeforeExit(code: number): void {
72
+ const stackTrace: StackTraceError = this.traceError(
73
+ `Process will exit with code: ${code}`,
74
+ "BeforeExit",
75
+ status.SERVICE_UNAVAILABLE
76
+ );
77
+ LogMessageUtils.error(
78
+ "BeforeExit",
79
+ "process before exit",
80
+ stackTrace.stack,
81
+ `Process will exit with code: ${code}`,
82
+ status.SERVICE_UNAVAILABLE
83
+ );
84
+ process.exit(code);
85
+ }
86
+ static processDisconnected(): void {
87
+ const stackTrace: StackTraceError = this.traceError(
88
+ "Child process disconnected",
89
+ "process disconnected",
90
+ status.SERVICE_UNAVAILABLE
91
+ );
92
+ LogMessageUtils.error(
93
+ "Disconnected",
94
+ "process disconnected",
95
+ stackTrace.stack,
96
+ "Child process disconnected",
97
+ status.SERVICE_UNAVAILABLE
98
+ );
99
+ process.exit();
100
+ }
101
+ static exited(code: number){
102
+ switch (code) {
103
+ case 0:
104
+ LogMessageUtils.success(
105
+ "Exited",
106
+ "completed",
107
+ "The process finished as expected and everything is ok"
108
+ );
109
+ console.log("");
110
+ const paddingLength: number = 35;
111
+ const msg0: string = ' '.padEnd(paddingLength, ' ');
112
+ console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, ' ')));
113
+ console.log(`${colors.bgGreen(` [OK] The server shutting down `)}`);
114
+ console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, ' ')));
115
+ break;
116
+ case 1:
117
+ const gnleStackTrace: StackTraceError = this.traceError(
118
+ "Something went wrong",
119
+ "General Errors",
120
+ status.SERVICE_UNAVAILABLE
121
+ );
122
+ LogMessageUtils.error(
123
+ "Exited",
124
+ "General Errors",
125
+ gnleStackTrace.stack,
126
+ "Something went wrong",
127
+ status.SERVICE_UNAVAILABLE
128
+ );
129
+ break
130
+ case 2:
131
+ const incrCmdStackTrace: StackTraceError = this.traceError(
132
+ "Incorrect using of shell commands",
133
+ "Misuse of shell builtins",
134
+ status.SERVICE_UNAVAILABLE
135
+ );
136
+ LogMessageUtils.error(
137
+ "Exited",
138
+ incrCmdStackTrace.name,
139
+ incrCmdStackTrace.stack,
140
+ "Incorrect using of shell commands",
141
+ status.SERVICE_UNAVAILABLE
142
+ );
143
+ break;
144
+ case 126:
145
+ const notExeCmdStackTrace: StackTraceError = this.traceError(
146
+ "Incorrect using of shell commands",
147
+ "Misuse of shell builtins",
148
+ status.SERVICE_UNAVAILABLE
149
+ );
150
+ LogMessageUtils.error(
151
+ "Exited",
152
+ `command invoked`,
153
+ notExeCmdStackTrace.stack,
154
+ "The command is found but is not executable (e.g., trying to execute a directory)",
155
+ status.SERVICE_UNAVAILABLE
156
+ );
157
+ break
158
+ case 127:
159
+ const cmdNotFoundStackTrace: StackTraceError = this.traceError(
160
+ "The command was not found in the system's PATH or is misspelled",
161
+ "Exited",
162
+ status.SERVICE_UNAVAILABLE
163
+ );
164
+ LogMessageUtils.error(
165
+ "Exited",
166
+ "Command not found",
167
+ cmdNotFoundStackTrace.stack,
168
+ "The command was not found in the system's PATH or is misspelled",
169
+ status.SERVICE_UNAVAILABLE
170
+ );
171
+ break;
172
+ case 128:
173
+ const cmdSysNotFoundStackTrace: StackTraceError = this.traceError(
174
+ "The command was not found in the system's PATH or is misspelled",
175
+ "Exited",
176
+ status.SERVICE_UNAVAILABLE
177
+ );
178
+ LogMessageUtils.error(
179
+ "Exited",
180
+ "Invalid argument",
181
+ cmdSysNotFoundStackTrace.stack,
182
+ "The command was not found in the system's PATH or is misspelled",
183
+ status.SERVICE_UNAVAILABLE
184
+ );
185
+ break;
186
+ case 130:
187
+ const endScriptStackTrace: StackTraceError = this.traceError(
188
+ "Indicates that the script was manually terminated by the user using the Control-C (SIGINT) signal",
189
+ "Exited",
190
+ status.SERVICE_UNAVAILABLE
191
+ );
192
+ LogMessageUtils.error(
193
+ "Exited",
194
+ "Script terminated",
195
+ endScriptStackTrace.stack,
196
+ "Indicates that the script was manually terminated by the user using the Control-C (SIGINT) signal",
197
+ status.SERVICE_UNAVAILABLE
198
+ );
199
+ break;
200
+ case 137:
201
+ const prcKillStackTrace: StackTraceError = this.traceError(
202
+ "Indicates that the process was terminated by a SIGKILL signal, possibly due to an out-of-memory situation",
203
+ "Exited",
204
+ status.SERVICE_UNAVAILABLE
205
+ );
206
+ LogMessageUtils.error(
207
+ "Exited",
208
+ "SIGKILL",
209
+ prcKillStackTrace.stack,
210
+ "Indicates that the process was terminated by a SIGKILL signal, possibly due to an out-of-memory situation",
211
+ status.SERVICE_UNAVAILABLE
212
+ );
213
+ break;
214
+ case 139:
215
+ const illegalAccessStackTrace: StackTraceError = this.traceError(
216
+ "Indicates that the process accessed an illegal memory address (segfault)",
217
+ "Exited",
218
+ status.SERVICE_UNAVAILABLE
219
+ );
220
+ LogMessageUtils.error(
221
+ "Exited",
222
+ "Segmentation fault",
223
+ illegalAccessStackTrace.stack,
224
+ "Indicates that the process accessed an illegal memory address (segfault)",
225
+ status.SERVICE_UNAVAILABLE
226
+ );
227
+ break;
228
+ case 143:
229
+ const sigtermStackTrace: StackTraceError = this.traceError(
230
+ "Indicates that the process received a SIGTERM signal to terminate",
231
+ "Exited",
232
+ status.SERVICE_UNAVAILABLE
233
+ );
234
+ LogMessageUtils.error(
235
+ "Exited",
236
+ "process received a SIGTERM",
237
+ sigtermStackTrace.stack,
238
+ "Indicates that the process received a SIGTERM signal to terminate",
239
+ status.SERVICE_UNAVAILABLE
240
+ );
241
+ break;
242
+ case 255:
243
+ const outsideStackTrace: StackTraceError = this.traceError(
244
+ "An exit code that is outside the allowable range (0-255 for Unix-like systems)",
245
+ "Exited",
246
+ status.SERVICE_UNAVAILABLE
247
+ );
248
+ LogMessageUtils.error(
249
+ "Exited",
250
+ "out of range",
251
+ outsideStackTrace.stack,
252
+ "An exit code that is outside the allowable range (0-255 for Unix-like systems)",
253
+ status.SERVICE_UNAVAILABLE
254
+ );
255
+ break;
256
+ default:
257
+ const globalStackTrace: StackTraceError = this.traceError(
258
+ "Error is occurring",
259
+ "Exited",
260
+ status.SERVICE_UNAVAILABLE
261
+ );
262
+ LogMessageUtils.error(
263
+ "Exited",
264
+ "errors",
265
+ globalStackTrace.stack,
266
+ "Error is occurring",
267
+ status.SERVICE_UNAVAILABLE
268
+ );
269
+ break;
270
+ }
271
+ }
272
+ static promiseRejectionHandled(promise: Promise<any>): void {
273
+ const globalStackTrace: StackTraceError = this.traceError(
274
+ `Promise rejection is handled at : ${promise}`,
275
+ "rejection promise",
276
+ status.SERVICE_UNAVAILABLE
277
+ );
278
+ LogMessageUtils.error(
279
+ "PromiseRejectionHandled",
280
+ "rejection promise",
281
+ globalStackTrace.stack,
282
+ `Promise rejection is handled at : ${promise}`,
283
+ status.SERVICE_UNAVAILABLE
284
+ );
285
+ }
286
+ static uncaughtException(error: any): void {
287
+ if (error.message === '\'app.router\' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.') {
288
+ console.log("");
289
+ } else {
290
+ const tackTrace: StackTraceError = this.traceError(
291
+ error.message,
292
+ "uncaught exception handled",
293
+ status.SERVICE_UNAVAILABLE
294
+ );
295
+ LogMessageUtils.error(
296
+ "UncaughtException",
297
+ "uncaught exception handled",
298
+ tackTrace.stack,
299
+ error.message,
300
+ status.SERVICE_UNAVAILABLE
301
+ );
302
+ }
303
+ }
304
+ static uncaughtExceptionMonitor(error: any): void {
305
+ if (error.message === '\'app.router\' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.') {
306
+ console.log("");
307
+ }
308
+ }
309
+ static unhandledRejection(reason: any, promise: Promise<any>): void{
310
+ const stackTrace: StackTraceError = this.traceError(
311
+ `Unhandled Rejection at: Promise ${promise} -- reason ${reason}`,
312
+ "Unhandled rejection",
313
+ status.SERVICE_UNAVAILABLE
314
+ );
315
+ LogMessageUtils.error(
316
+ "UnhandledRejection",
317
+ "Unhandled rejection",
318
+ stackTrace.stack,
319
+ `Unhandled Rejection at: Promise ${promise} -- reason ${reason}`,
320
+ status.SERVICE_UNAVAILABLE
321
+ );
322
+ }
323
+ static warning(warning: any): void {
324
+ const stackTrace: StackTraceError = this.traceError(warning.message, "warning", status.SERVICE_UNAVAILABLE);
325
+ LogMessageUtils.error(
326
+ "Warning",
327
+ "warning",
328
+ stackTrace.stack,
329
+ warning.message,
330
+ status.SERVICE_UNAVAILABLE
331
+ );
332
+ }
333
+ static message(message: any): void {
334
+ const stackTrace: StackTraceError = this.traceError(
335
+ `process got message ${message}`,
336
+ "message exception",
337
+ status.SERVICE_UNAVAILABLE
338
+ );
339
+ LogMessageUtils.error(
340
+ "Message",
341
+ "message exception",
342
+ stackTrace.stack,
343
+ `process got message ${message}`,
344
+ status.SERVICE_UNAVAILABLE
345
+ );
346
+ }
347
+ static multipleResolves(type: string, promise: Promise<any>, reason: any): void {
348
+ const stackTrace: StackTraceError = this.traceError(
349
+ `${promise} -- ${reason}`,
350
+ "multipleResolves",
351
+ status.SERVICE_UNAVAILABLE
352
+ );
353
+ LogMessageUtils.error(
354
+ "multipleResolves",
355
+ `Multiple resolves detected : ${type}`,
356
+ stackTrace.stack,
357
+ `${promise} -- ${reason}`,
358
+ status.SERVICE_UNAVAILABLE
359
+ );
360
+ }
361
+ static processInterrupted(): void {
362
+ LogMessageUtils.success(
363
+ "[ OK ] Success",
364
+ `Process ${process.pid} has been interrupted`,
365
+ "The Web server has been stopped !"
366
+ );
367
+ process.exit(0);
368
+ }
369
+ static sigtermSignalReceived(signal: any): void {
370
+ const stackTrace: StackTraceError = this.traceError(
371
+ `Process ${process.pid} received a SIGTERM signal`,
372
+ "SIGTERM",
373
+ status.NOT_ACCEPTABLE
374
+ );
375
+ LogMessageUtils.error(
376
+ "SIGTERM",
377
+ "SIGTERM",
378
+ stackTrace.stack,
379
+ `Process ${process.pid} received a SIGTERM signal : ${signal.toString()}`,
380
+ status.NOT_ACCEPTABLE
381
+ );
382
+ process.exit(0);
383
+ }
384
+ static serverClosing(): void {
385
+ console.log(`${colors.bgCyanBright(` ${colors.bold(`${colors.white(` INFO `)}`)}`)} All processes are stopped`);
386
+ console.log(" Server is closed");
387
+ process.exit();
388
+ }
389
+ static dropNewConnection(): void {
390
+ console.log(`${colors.cyan(`ⓘ`)} ${colors.bgCyan(` ${colors.bold(`${colors.white(` Server maxConnection `)}`)} `)} ${currentDate} | ${colors.bgCyan(`${colors.white(` Info `)}`)} The server dropped new connections`);
391
+ }
392
+ static expressErrorHandlingMiddleware(errorEmitter: any,
393
+ err: Error,
394
+ req: express.Request,
395
+ res: express.Response,
396
+ next: express.NextFunction): void {
397
+ if (err) {
398
+ errorEmitter.emit(eventName.error, err);
399
+ if (typeof res.status === 'function') {
400
+ res.status(500).send('Internal Server Error');
401
+ } else {
402
+ console.error('res.status is not a function');
403
+ }
404
+
405
+ const stackTrace: StackTraceError = this.traceError(err.message, "Express error", status.NOT_ACCEPTABLE);
406
+ LogMessageUtils.error(
407
+ "Express error-handling middleware",
408
+ "Express error",
409
+ stackTrace.stack,
410
+ err.message,
411
+ status.SERVICE_UNAVAILABLE
412
+ )
413
+ } else {
414
+ next();
415
+ }
416
+ }
417
+
418
+ private static traceError(props: string, name: string, status: number): StackTraceError {
419
+ return new StackTraceError(props, name, status, true);
420
+ }
421
+ }
@@ -0,0 +1,86 @@
1
+ import colors from "ansi-colors";
2
+ import {IncomingMessage, ServerResponse} from "node:http";
3
+ import {LoggerCore} from "opticore-logger";
4
+
5
+ export function requestCallsEvent(req: IncomingMessage, res: ServerResponse, host: string, port: number, loadingTime: any) {
6
+ const logger: LoggerCore = new LoggerCore();
7
+
8
+ const currentDatePath: string = `Request called`;
9
+ // @ts-ignore
10
+ if(req.originalUrl === "undefined") {
11
+ console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] The route do not exist. - [ Status ] ${colors.red(`${colors.white(` 404 `)}`)}`);
12
+ logger.error("The route do not exist.");
13
+ } else {
14
+ switch (res.statusCode) {
15
+ case 200:
16
+ switch (req.method) {
17
+ case 'POST': // @ts-ignore
18
+ console.log(`[ ${colors.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgGreen(`${colors.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgCyan(`${colors.white(` 200 `)}`)}`); // @ts-ignore
19
+ logger.info(`[ ${colors.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgGreen(`${colors.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgCyan(`${colors.white(` 200 `)}`)}`);
20
+ break;
21
+ case 'GET':
22
+ case 'PUT': // @ts-ignore
23
+ console.log(`[ ${colors.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgGreen(`${colors.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.bgCyan(`${colors.white(` 200 `)}`)}`); // @ts-ignore
24
+ logger.info(`[ ${colors.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgGreen(`${colors.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.bgCyan(`${colors.white(` 200 `)}`)}`);
25
+ break;
26
+ case 'DELETE': // @ts-ignore
27
+ console.log(`[ ${colors.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgGreen(`${colors.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.bgCyan(`${colors.white(` 200 `)}`)}`);// @ts-ignore
28
+ logger.info(`[ ${colors.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgGreen(`${colors.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.bgCyan(`${colors.white(` 200 `)}`)}`);
29
+ break;
30
+ }
31
+ break;
32
+ case 404:
33
+ switch (req.method) {
34
+ case 'POST': // @ts-ignore
35
+ console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.red(`${colors.white(` 404 `)}`)}`);
36
+ break;
37
+ case 'GET': // @ts-ignore
38
+ console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.red(`${colors.bold(` 404 `)}`)}`);
39
+ break;
40
+ case 'PUT': // @ts-ignore
41
+ console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.red(`${colors.bold(` 404 `)}`)}`);
42
+ break;
43
+ case 'DELETE': // @ts-ignore
44
+ console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.red(`${colors.bold(` 404 `)}`)}`);
45
+ break;
46
+ }
47
+ break;
48
+ case 401:
49
+ switch (req.method) {
50
+ case 'POST': // @ts-ignore
51
+ console.log(`[ ${colors.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgYellowBright(`${colors.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgYellow(`${colors.bold(` 401 `)}`)}`);
52
+ break;
53
+ case 'GET': // @ts-ignore
54
+ console.log(`[ ${colors.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgYellowBright(`${colors.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgYellow(`${colors.bold(` 401 `)}`)}`);
55
+ break;
56
+ case 'PUT': // @ts-ignore
57
+ console.log(`[ ${colors.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgYellowBright(`${colors.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgYellow(`${colors.bold(` 401 `)}`)}`);
58
+ break;
59
+ case 'DELETE': // @ts-ignore
60
+ console.log(`[ ${colors.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgYellowBright(`${colors.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgYellow(`${colors.bold(` 401 `)}`)}`);
61
+ break;
62
+ }
63
+ break;
64
+ case 500:
65
+ switch (req.method) {
66
+ case 'POST': // @ts-ignore
67
+ console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.red(`${colors.bold(` 500 `)}`)}`);
68
+ break;
69
+ case 'GET': // @ts-ignore
70
+ console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.red(`${colors.bold(` 500 `)}`)}`);
71
+ break;
72
+ case 'PUT': // @ts-ignore
73
+ console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.red(`${colors.bold(` 500 `)}`)}`);
74
+ break;
75
+ case 'DELETE': // @ts-ignore
76
+ console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.red(`${colors.bold(` 500 `)}`)}`);
77
+ break;
78
+ }
79
+ break;
80
+ default:
81
+ // @ts-ignore
82
+ console.log(`[ ${colors.blueBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.blueBright(` ${res.statusMessage} `)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.blueBright(` ${res.req.socket._httpMessage.statusCode} `)}`);
83
+ break;
84
+ }
85
+ }
86
+ }
@@ -0,0 +1,23 @@
1
+ import {HttpStatusCodesConstant} from "@webApp/domains/constants/httpStatusCodes.constant";
2
+
3
+
4
+ /**
5
+ * Handling and catch a Node.js error.
6
+ */
7
+ export default class StackTraceError extends Error {
8
+ public readonly name: string;
9
+ public readonly httpCode: HttpStatusCodesConstant | any;
10
+ public readonly isOperational: boolean;
11
+
12
+ // Centralized error objet that derives from Node's Error.
13
+ constructor(props: string | undefined, name: string, httpCode: HttpStatusCodesConstant | any, isOperational: boolean) {
14
+ super(props);
15
+
16
+ Object.setPrototypeOf(this, new.target.prototype);
17
+ this.name = name;
18
+ this.httpCode = httpCode;
19
+ this.isOperational = isOperational;
20
+
21
+ Error.captureStackTrace(this);
22
+ }
23
+ }
@@ -0,0 +1,13 @@
1
+ import StackTraceError from "./base/stackTraceError";
2
+ import {CErrorName as errorName} from "@webApp/domains/constants/errorName.constant";
3
+ import {HttpStatusCodesConstant as status} from "@webApp/domains/constants/httpStatusCodes.constant";
4
+
5
+
6
+ /**
7
+ * Handling and catch a Node.js error.
8
+ */
9
+ export default class StackTraceAssertionError extends StackTraceError {
10
+ constructor(message: string) {
11
+ super(message, errorName.evalError, status.INTERNAL_SERVER_ERROR, true);
12
+ }
13
+ }
@@ -0,0 +1,12 @@
1
+ import StackTraceError from "./base/stackTraceError";
2
+ import {errorNameConstant} from "../../utils/constants/errorName.constant";
3
+ import {HttpStatusCodesConstant as status} from "../../../domain/constants/httpStatusCodes.constant";
4
+
5
+ /**
6
+ * Handling and catch a Node.js error.
7
+ */
8
+ export default class StackTraceEvalError extends StackTraceError {
9
+ constructor(message: string) {
10
+ super(message, errorNameConstant.evalError, status.BAD_REQUEST, true);
11
+ }
12
+ }
@@ -0,0 +1,13 @@
1
+ import StackTraceError from "./base/stackTraceError";
2
+ import {errorNameConstant} from "../../utils/constants/errorName.constant";
3
+ import {HttpStatusCodesConstant as status} from "../../../domain/constants/httpStatusCodes.constant";
4
+
5
+
6
+ /**
7
+ * Handling and catch a Node.js error.
8
+ */
9
+ export default class StackTraceGeneralError extends StackTraceError {
10
+ constructor(message: string) {
11
+ super(message, errorNameConstant.evalError, status.INTERNAL_SERVER_ERROR, false);
12
+ }
13
+ }
@@ -0,0 +1,12 @@
1
+ import StackTraceError from "./base/stackTraceError";
2
+ import {errorNameConstant} from "../../utils/constants/errorName.constant";
3
+ import {HttpStatusCodesConstant as status} from "../../../domain/constants/httpStatusCodes.constant";
4
+
5
+ /**
6
+ * Handling and catch a Node.js error.
7
+ */
8
+ export default class StackTraceOpenSSLError extends StackTraceError {
9
+ constructor(message: string) {
10
+ super(message, errorNameConstant.evalError, status.INTERNAL_SERVER_ERROR, false);
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ import StackTraceError from "./base/stackTraceError";
2
+ import {errorNameConstant} from "../../utils/constants/errorName.constant";
3
+ import {HttpStatusCodesConstant as status} from "../../../domain/constants/httpStatusCodes.constant";
4
+
5
+ /**
6
+ * Handling and catch a Node.js error.
7
+ */
8
+ export default class StackTraceRangeError extends StackTraceError {
9
+ constructor(message: string) {
10
+ super(message, errorNameConstant.evalError, status.BAD_REQUEST, true);
11
+ }
12
+ }
@@ -0,0 +1,13 @@
1
+ import StackTraceError from "./base/stackTraceError";
2
+ import {errorNameConstant} from "../../utils/constants/errorName.constant";
3
+ import {HttpStatusCodesConstant as status} from "../../../domain/constants/httpStatusCodes.constant";
4
+
5
+
6
+ /**
7
+ * Handling and catch a Node.js error.
8
+ */
9
+ export default class StackTraceReferenceError extends StackTraceError {
10
+ constructor(message: string) {
11
+ super(message, errorNameConstant.evalError, status.BAD_REQUEST, true);
12
+ }
13
+ }
@@ -0,0 +1,12 @@
1
+ import StackTraceError from "./base/stackTraceError";
2
+ import {errorNameConstant} from "../../utils/constants/errorName.constant";
3
+ import {HttpStatusCodesConstant as status} from "../../../domain/constants/httpStatusCodes.constant";
4
+
5
+ /**
6
+ * Handling and catch a Node.js error.
7
+ */
8
+ export default class StackTraceSyntaxError extends StackTraceError {
9
+ constructor(message: string) {
10
+ super(message, errorNameConstant.evalError, status.BAD_REQUEST, true);
11
+ }
12
+ }
@@ -0,0 +1,14 @@
1
+ import StackTraceError from "./base/stackTraceError";
2
+ import {errorNameConstant} from "../../utils/constants/errorName.constant";
3
+ import {HttpStatusCodesConstant as status} from "../../../domain/constants/httpStatusCodes.constant";
4
+
5
+
6
+ /**
7
+ * Handling and catch a Node.js error.
8
+ */
9
+ export default class StackTraceSystemError extends StackTraceError {
10
+ constructor(message: string, code: string) {
11
+ super(message, errorNameConstant.systemError, status.INTERNAL_SERVER_ERROR, false);
12
+ this.message = `${message} (code: ${code})`;
13
+ }
14
+ }
@@ -0,0 +1,13 @@
1
+ import StackTraceError from "./base/stackTraceError";
2
+ import {errorNameConstant} from "../../utils/constants/errorName.constant";
3
+ import {HttpStatusCodesConstant as status} from "../../../domain/constants/httpStatusCodes.constant";
4
+
5
+
6
+ /**
7
+ * Handling and catch a Node.js error.
8
+ */
9
+ export default class StackTraceTypeError extends StackTraceError {
10
+ constructor(message: string) {
11
+ super(message, errorNameConstant.evalError, status.BAD_REQUEST, true);
12
+ }
13
+ }