opticore-catch-exception-error 1.0.0 → 1.0.2

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.
package/dist/index.cjs CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -23,6 +33,7 @@ __export(index_exports, {
23
33
  CErrorName: () => CErrorName,
24
34
  CEvent: () => CEvent,
25
35
  CEventNameError: () => CEventNameError,
36
+ ServerListenEventError: () => ServerListenEventError,
26
37
  StackTraceAssertionError: () => StackTraceAssertionError,
27
38
  StackTraceError: () => StackTraceError,
28
39
  StackTraceEvalError: () => StackTraceEvalError,
@@ -177,11 +188,532 @@ var StackTraceURIError = class extends StackTraceError {
177
188
  super(message, CErrorName.evalError, import_opticore_http_response10.HttpStatusCode.BAD_REQUEST, true);
178
189
  }
179
190
  };
191
+
192
+ // src/core/errors/events/serverListen.event.error.ts
193
+ var import_process = __toESM(require("process"), 1);
194
+ var import_ansi_colors = __toESM(require("ansi-colors"), 1);
195
+ var import_chalk = __toESM(require("chalk"), 1);
196
+ var import_opticore_logger = require("opticore-logger");
197
+ var import_opticore_http_response11 = require("opticore-http-response");
198
+ var import_opticore_translator = require("opticore-translator");
199
+
200
+ // src/utils/dateTimeFormatted.utils.ts
201
+ var dateTimeFormatted = `${(/* @__PURE__ */ new Date()).getMonth()}-${(/* @__PURE__ */ new Date()).getDate()}-${(/* @__PURE__ */ new Date()).getFullYear()} ${(/* @__PURE__ */ new Date()).getHours()}:${(/* @__PURE__ */ new Date()).getMinutes()}:${(/* @__PURE__ */ new Date()).getSeconds()}`;
202
+
203
+ // src/core/errors/events/serverListen.event.error.ts
204
+ var ServerListenEventError = class {
205
+ /**
206
+ *
207
+ */
208
+ static hostPortUndefined() {
209
+ this.stackTrace = this.traceError(
210
+ import_opticore_translator.TranslationLoader.t("errorHostUrl", import_opticore_translator.CLocal),
211
+ import_opticore_translator.TranslationLoader.t("listening", import_opticore_translator.CLocal),
212
+ import_opticore_http_response11.HttpStatusCode.BAD_REQUEST
213
+ );
214
+ this.logger.error(
215
+ this.stackTrace.message,
216
+ import_opticore_translator.TranslationLoader.t("webServer", import_opticore_translator.CLocal),
217
+ import_opticore_translator.TranslationLoader.t("badHost", import_opticore_translator.CLocal),
218
+ this.stackTrace.stack,
219
+ import_opticore_http_response11.HttpStatusCode.BAD_REQUEST
220
+ );
221
+ import_process.default.exit();
222
+ }
223
+ /**
224
+ *
225
+ */
226
+ static hostUndefined() {
227
+ this.stackTrace = this.traceError(
228
+ import_opticore_translator.TranslationLoader.t("badHost", import_opticore_translator.CLocal),
229
+ import_opticore_translator.TranslationLoader.t("listening", import_opticore_translator.CLocal),
230
+ import_opticore_http_response11.HttpStatusCode.BAD_REQUEST
231
+ );
232
+ this.logger.error(
233
+ this.stackTrace.message,
234
+ import_opticore_translator.TranslationLoader.t("webServer", import_opticore_translator.CLocal),
235
+ import_opticore_translator.TranslationLoader.t("badHost", import_opticore_translator.CLocal),
236
+ this.stackTrace.stack,
237
+ import_opticore_http_response11.HttpStatusCode.BAD_REQUEST
238
+ );
239
+ import_process.default.exit();
240
+ }
241
+ /**
242
+ *
243
+ */
244
+ static portUndefined() {
245
+ this.stackTrace = this.traceError(
246
+ import_opticore_translator.TranslationLoader.t("badPort", import_opticore_translator.CLocal),
247
+ import_opticore_translator.TranslationLoader.t("listening", import_opticore_translator.CLocal),
248
+ import_opticore_http_response11.HttpStatusCode.BAD_REQUEST
249
+ );
250
+ this.logger.error(
251
+ this.stackTrace.message,
252
+ import_opticore_translator.TranslationLoader.t("webServer", import_opticore_translator.CLocal),
253
+ import_opticore_translator.TranslationLoader.t("badHost", import_opticore_translator.CLocal),
254
+ this.stackTrace.stack,
255
+ import_opticore_http_response11.HttpStatusCode.BAD_REQUEST
256
+ );
257
+ import_process.default.exit();
258
+ }
259
+ /**
260
+ *
261
+ * @param err
262
+ */
263
+ static onEventError(err) {
264
+ this.logger.error(
265
+ import_opticore_translator.TranslationLoader.t(err.message, import_opticore_translator.CLocal),
266
+ import_opticore_translator.TranslationLoader.t("serverStart", import_opticore_translator.CLocal),
267
+ import_opticore_translator.TranslationLoader.t("serverStartError", import_opticore_translator.CLocal),
268
+ err.stack,
269
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
270
+ );
271
+ }
272
+ /**
273
+ *
274
+ * @param error
275
+ */
276
+ static listenerError(error) {
277
+ this.stackTrace = this.traceError(
278
+ error.message,
279
+ error.name,
280
+ import_opticore_http_response11.HttpStatusCode.BAD_REQUEST
281
+ );
282
+ this.logger.error(
283
+ this.stackTrace.message,
284
+ "Event error",
285
+ "Error",
286
+ error.stack,
287
+ import_opticore_http_response11.HttpStatusCode.BAD_REQUEST
288
+ );
289
+ }
290
+ /**
291
+ *
292
+ * @param code
293
+ */
294
+ static processBeforeExit(code) {
295
+ this.stackTrace = this.traceError(
296
+ import_opticore_translator.TranslationLoader.t("processExitCode", import_opticore_translator.CLocal, { processExitCode: code }),
297
+ import_opticore_translator.TranslationLoader.t("beforeExit", import_opticore_translator.CLocal),
298
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
299
+ );
300
+ this.logger.error(
301
+ this.stackTrace.message,
302
+ import_opticore_translator.TranslationLoader.t("beforeExit", import_opticore_translator.CLocal),
303
+ import_opticore_translator.TranslationLoader.t("processBeforeExit", import_opticore_translator.CLocal),
304
+ this.stackTrace.stack,
305
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
306
+ );
307
+ import_process.default.exit(code);
308
+ }
309
+ /**
310
+ *
311
+ */
312
+ static processDisconnected() {
313
+ this.stackTrace = this.traceError(
314
+ import_opticore_translator.TranslationLoader.t("childProcessDiscon", import_opticore_translator.CLocal),
315
+ import_opticore_translator.TranslationLoader.t("processDiscon", import_opticore_translator.CLocal),
316
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
317
+ );
318
+ this.logger.error(
319
+ this.stackTrace.message,
320
+ import_opticore_translator.TranslationLoader.t("disconnected"),
321
+ import_opticore_translator.TranslationLoader.t("processDiscon"),
322
+ this.stackTrace.stack,
323
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
324
+ );
325
+ import_process.default.exit();
326
+ }
327
+ /**
328
+ *
329
+ * @param code
330
+ */
331
+ static exited(code) {
332
+ switch (code) {
333
+ case 0:
334
+ this.logger.success(
335
+ import_opticore_translator.TranslationLoader.t("completed", import_opticore_translator.CLocal, {}),
336
+ import_opticore_translator.TranslationLoader.t("finishingProcessWell", import_opticore_translator.CLocal, { code })
337
+ );
338
+ console.log("");
339
+ const paddingLength = 35;
340
+ const msg0 = " ".padEnd(paddingLength, " ");
341
+ console.log(import_chalk.default.bgGreen.white(msg0.padEnd(paddingLength, " ")));
342
+ console.log(`${import_ansi_colors.default.bgGreen(` ${import_opticore_translator.TranslationLoader.t("serverStopped", import_opticore_translator.CLocal)} `)}`);
343
+ console.log(import_chalk.default.bgGreen.white(msg0.padEnd(paddingLength, " ")));
344
+ break;
345
+ case 1:
346
+ this.stackTrace = this.traceError(
347
+ import_opticore_translator.TranslationLoader.t("somethingWentWrong", import_opticore_translator.CLocal),
348
+ import_opticore_translator.TranslationLoader.t("genErrors", import_opticore_translator.CLocal),
349
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
350
+ );
351
+ this.logger.error(
352
+ this.stackTrace.message,
353
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
354
+ "General Errors",
355
+ this.stackTrace.stack,
356
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
357
+ );
358
+ break;
359
+ case 2:
360
+ this.stackTrace = this.traceError(
361
+ import_opticore_translator.TranslationLoader.t("incorrectCmd", import_opticore_translator.CLocal),
362
+ import_opticore_translator.TranslationLoader.t("misuseShell", import_opticore_translator.CLocal),
363
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
364
+ );
365
+ this.logger.error(
366
+ this.stackTrace.message,
367
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
368
+ import_opticore_translator.TranslationLoader.t("incorrectCmd", import_opticore_translator.CLocal),
369
+ this.stackTrace.stack,
370
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
371
+ );
372
+ break;
373
+ case 126:
374
+ this.stackTrace = this.traceError(
375
+ import_opticore_translator.TranslationLoader.t("incorrectCmd", import_opticore_translator.CLocal),
376
+ import_opticore_translator.TranslationLoader.t("cmdNotExecutable", import_opticore_translator.CLocal),
377
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
378
+ );
379
+ this.logger.error(
380
+ this.stackTrace.message,
381
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
382
+ this.stackTrace.name,
383
+ this.stackTrace.stack,
384
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
385
+ );
386
+ break;
387
+ case 127:
388
+ this.stackTrace = this.traceError(
389
+ import_opticore_translator.TranslationLoader.t("cmdNotFound", import_opticore_translator.CLocal),
390
+ import_opticore_translator.TranslationLoader.t("cmdNotFoundInSystemPath", import_opticore_translator.CLocal),
391
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
392
+ );
393
+ this.logger.error(
394
+ this.stackTrace.message,
395
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
396
+ this.stackTrace.name,
397
+ this.stackTrace.stack,
398
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
399
+ );
400
+ break;
401
+ case 128:
402
+ this.stackTrace = this.traceError(
403
+ import_opticore_translator.TranslationLoader.t("cmdNotFoundInSystemPath", import_opticore_translator.CLocal),
404
+ import_opticore_translator.TranslationLoader.t("argInvalid", import_opticore_translator.CLocal),
405
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
406
+ );
407
+ this.logger.error(
408
+ this.stackTrace.message,
409
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
410
+ this.stackTrace.name,
411
+ this.stackTrace.stack,
412
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
413
+ );
414
+ break;
415
+ case 130:
416
+ this.stackTrace = this.traceError(
417
+ import_opticore_translator.TranslationLoader.t("scriptEndedManuallyByCtrlC", import_opticore_translator.CLocal),
418
+ import_opticore_translator.TranslationLoader.t("scriptEnded", import_opticore_translator.CLocal),
419
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
420
+ );
421
+ this.logger.error(
422
+ this.stackTrace.message,
423
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
424
+ this.stackTrace.name,
425
+ this.stackTrace.stack,
426
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
427
+ );
428
+ break;
429
+ case 137:
430
+ this.stackTrace = this.traceError(
431
+ import_opticore_translator.TranslationLoader.t("processEndedBySIGKILL", import_opticore_translator.CLocal),
432
+ "SIGKILL",
433
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
434
+ );
435
+ this.logger.error(
436
+ this.stackTrace.message,
437
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
438
+ this.stackTrace.name,
439
+ this.stackTrace.stack,
440
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
441
+ );
442
+ break;
443
+ case 139:
444
+ this.stackTrace = this.traceError(
445
+ import_opticore_translator.TranslationLoader.t("accessProcessIllegally", import_opticore_translator.CLocal),
446
+ import_opticore_translator.TranslationLoader.t("defaultSegment", import_opticore_translator.CLocal),
447
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
448
+ );
449
+ this.logger.error(
450
+ this.stackTrace.message,
451
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
452
+ this.stackTrace.name,
453
+ this.stackTrace.stack,
454
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
455
+ );
456
+ break;
457
+ case 143:
458
+ this.stackTrace = this.traceError(
459
+ import_opticore_translator.TranslationLoader.t("processReceivedSigtermSignal", import_opticore_translator.CLocal),
460
+ import_opticore_translator.TranslationLoader.t("processReceived", import_opticore_translator.CLocal),
461
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
462
+ );
463
+ this.logger.error(
464
+ this.stackTrace.message,
465
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
466
+ this.stackTrace.name,
467
+ this.stackTrace.stack,
468
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
469
+ );
470
+ break;
471
+ case 255:
472
+ this.stackTrace = this.traceError(
473
+ import_opticore_translator.TranslationLoader.t("exitCode", import_opticore_translator.CLocal),
474
+ import_opticore_translator.TranslationLoader.t("outRange", import_opticore_translator.CLocal),
475
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
476
+ );
477
+ this.logger.error(
478
+ this.stackTrace.message,
479
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
480
+ this.stackTrace.name,
481
+ this.stackTrace.stack,
482
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
483
+ );
484
+ break;
485
+ default:
486
+ this.stackTrace = this.traceError(
487
+ import_opticore_translator.TranslationLoader.t("errorOccurring", import_opticore_translator.CLocal),
488
+ import_opticore_translator.TranslationLoader.t("errors", import_opticore_translator.CLocal),
489
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
490
+ );
491
+ this.logger.error(
492
+ this.stackTrace.message,
493
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
494
+ this.stackTrace.name,
495
+ this.stackTrace.stack,
496
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
497
+ );
498
+ break;
499
+ }
500
+ }
501
+ /**
502
+ *
503
+ * @param promise
504
+ */
505
+ static promiseRejectionHandled(promise) {
506
+ try {
507
+ this.stackTrace = this.traceError(
508
+ import_opticore_translator.TranslationLoader.t("promise", import_opticore_translator.CLocal, { promise }),
509
+ import_opticore_translator.TranslationLoader.t("rejectionPromise", import_opticore_translator.CLocal),
510
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
511
+ );
512
+ this.logger.error(
513
+ this.stackTrace.message,
514
+ "PromiseRejectionHandled",
515
+ this.stackTrace.name,
516
+ this.stackTrace.stack,
517
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
518
+ );
519
+ } catch (err) {
520
+ }
521
+ }
522
+ /**
523
+ *
524
+ * @param error
525
+ */
526
+ static uncaughtException(error) {
527
+ 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.") {
528
+ console.log("");
529
+ } else {
530
+ this.stackTrace = this.traceError(
531
+ import_opticore_translator.TranslationLoader.t(error.message),
532
+ import_opticore_translator.TranslationLoader.t("uncaughtExceptionHandled", import_opticore_translator.CLocal),
533
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
534
+ );
535
+ this.logger.error(
536
+ this.stackTrace.message,
537
+ "UncaughtException",
538
+ this.stackTrace.name,
539
+ this.stackTrace.stack,
540
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
541
+ );
542
+ }
543
+ }
544
+ /**
545
+ *
546
+ * @param error
547
+ */
548
+ static uncaughtExceptionMonitor(error) {
549
+ 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.") {
550
+ console.log("");
551
+ }
552
+ }
553
+ /**
554
+ *
555
+ * @param reason
556
+ * @param promise
557
+ */
558
+ static unhandledRejection(reason, promise) {
559
+ this.stackTrace = this.traceError(
560
+ import_opticore_translator.TranslationLoader.t("unhandledRejectionAtPromise", import_opticore_translator.CLocal, { promise, reason }),
561
+ import_opticore_translator.TranslationLoader.t("unhandledRejection", import_opticore_translator.CLocal),
562
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
563
+ );
564
+ this.logger.error(
565
+ this.stackTrace.message,
566
+ "UnhandledRejection",
567
+ this.stackTrace.name,
568
+ this.stackTrace.stack,
569
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
570
+ );
571
+ }
572
+ /**
573
+ *
574
+ * @param warning
575
+ */
576
+ static warning(warning) {
577
+ this.stackTrace = this.traceError(
578
+ import_opticore_translator.TranslationLoader.t(warning.message, import_opticore_translator.CLocal),
579
+ "warning",
580
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
581
+ );
582
+ this.logger.error(
583
+ this.stackTrace.message,
584
+ import_opticore_translator.TranslationLoader.t("warning", import_opticore_translator.CLocal),
585
+ this.stackTrace.name,
586
+ this.stackTrace.stack,
587
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
588
+ );
589
+ }
590
+ /**
591
+ *
592
+ * @param message
593
+ */
594
+ static message(message) {
595
+ this.stackTrace = this.traceError(
596
+ import_opticore_translator.TranslationLoader.t("processGotMsg", import_opticore_translator.CLocal, { message }),
597
+ import_opticore_translator.TranslationLoader.t("msgException", import_opticore_translator.CLocal),
598
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
599
+ );
600
+ this.logger.error(
601
+ this.stackTrace.message,
602
+ "Message",
603
+ this.stackTrace.name,
604
+ this.stackTrace.stack,
605
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
606
+ );
607
+ }
608
+ /**
609
+ *
610
+ * @param type
611
+ * @param promise
612
+ * @param reason
613
+ */
614
+ static multipleResolves(type, promise, reason) {
615
+ this.stackTrace = this.traceError(
616
+ import_opticore_translator.TranslationLoader.t("promiseReason", import_opticore_translator.CLocal, { promise, reason }),
617
+ import_opticore_translator.TranslationLoader.t("multipleResolvesDetected", import_opticore_translator.CLocal, { type }),
618
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
619
+ );
620
+ this.logger.error(
621
+ this.stackTrace.message,
622
+ "multipleResolves",
623
+ this.stackTrace.name,
624
+ this.stackTrace.stack,
625
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
626
+ );
627
+ }
628
+ /**
629
+ *
630
+ */
631
+ static processInterrupted() {
632
+ this.logger.success(import_opticore_translator.TranslationLoader.t("okSuccess", import_opticore_translator.CLocal), import_opticore_translator.TranslationLoader.t("serverWebStopped", import_opticore_translator.CLocal));
633
+ import_process.default.exit(0);
634
+ }
635
+ /**
636
+ *
637
+ * @param signal
638
+ */
639
+ static sigtermSignalReceived(signal) {
640
+ this.stackTrace = this.traceError(
641
+ import_opticore_translator.TranslationLoader.t("processPIDReceivedSignal", import_opticore_translator.CLocal, { signal: signal.toString() }),
642
+ "SIGTERM",
643
+ import_opticore_http_response11.HttpStatusCode.NOT_ACCEPTABLE
644
+ );
645
+ this.logger.error(
646
+ this.stackTrace.message,
647
+ "SIGTERM",
648
+ this.stackTrace.name,
649
+ this.stackTrace.stack,
650
+ import_opticore_http_response11.HttpStatusCode.NOT_ACCEPTABLE
651
+ );
652
+ import_process.default.exit(0);
653
+ }
654
+ /**
655
+ *
656
+ */
657
+ static serverClosing() {
658
+ console.log(`${import_ansi_colors.default.bgCyanBright(` ${import_ansi_colors.default.bold(`${import_ansi_colors.default.white(` INFO `)}`)}`)} ${import_opticore_translator.TranslationLoader.t("allProcessStopped", import_opticore_translator.CLocal)}`);
659
+ console.log(` ${import_opticore_translator.TranslationLoader.t("serverClosed", import_opticore_translator.CLocal)}`);
660
+ import_process.default.exit();
661
+ }
662
+ /**
663
+ *
664
+ */
665
+ static dropNewConnection() {
666
+ console.log(`${import_ansi_colors.default.cyan(`\u24D8`)} ${import_ansi_colors.default.bgCyan(` ${import_ansi_colors.default.bold(`${import_ansi_colors.default.white(` ${import_opticore_translator.TranslationLoader.t("serverMaxCon", import_opticore_translator.CLocal)} `)}`)} `)} ${dateTimeFormatted} | ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` Info `)}`)} ${import_opticore_translator.TranslationLoader.t("serverDroppedCon", import_opticore_translator.CLocal)}`);
667
+ }
668
+ /**
669
+ *
670
+ * @param errorEmitter
671
+ * @param err
672
+ * @param req
673
+ * @param res
674
+ * @param next
675
+ */
676
+ static expressErrorHandlingMiddleware(errorEmitter, err, req, res, next) {
677
+ if (err) {
678
+ errorEmitter.emit(CEventNameError.error, err);
679
+ if (typeof res.status === "function") {
680
+ res.status(500).send(import_opticore_translator.TranslationLoader.t("internalServerError", import_opticore_translator.CLocal, { err }));
681
+ } else {
682
+ this.logger.error(
683
+ import_opticore_translator.TranslationLoader.t("resStatusNotFunc", import_opticore_translator.CLocal, { err }),
684
+ "response status",
685
+ import_opticore_translator.TranslationLoader.t("respndNotFunc", import_opticore_translator.CLocal, { err }),
686
+ err.stack,
687
+ import_opticore_http_response11.HttpStatusCode.NOT_ACCEPTABLE
688
+ );
689
+ }
690
+ this.stackTrace = this.traceError(
691
+ err.message,
692
+ import_opticore_translator.TranslationLoader.t("expressError", import_opticore_translator.CLocal, { err }),
693
+ import_opticore_http_response11.HttpStatusCode.NOT_ACCEPTABLE
694
+ );
695
+ this.logger.error(
696
+ this.stackTrace.message,
697
+ import_opticore_translator.TranslationLoader.t("expressErrorHandlingMiddleware", import_opticore_translator.CLocal, { err }),
698
+ this.stackTrace.name,
699
+ this.stackTrace.stack,
700
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
701
+ );
702
+ } else {
703
+ next();
704
+ }
705
+ }
706
+ static traceError(props, name, status12) {
707
+ return new StackTraceError(props, name, status12, true);
708
+ }
709
+ };
710
+ ServerListenEventError.logger = new import_opticore_logger.LoggerCore();
180
711
  // Annotate the CommonJS export names for ESM import in node:
181
712
  0 && (module.exports = {
182
713
  CErrorName,
183
714
  CEvent,
184
715
  CEventNameError,
716
+ ServerListenEventError,
185
717
  StackTraceAssertionError,
186
718
  StackTraceError,
187
719
  StackTraceEvalError,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { HttpStatusCode } from 'opticore-http-response';
2
+ import EventEmitter from 'node:events';
3
+ import { Request, Response, NextFunction } from 'opticore-express';
2
4
 
3
5
  declare const CErrorName: {
4
6
  evalError: string;
@@ -125,4 +127,110 @@ declare class StackTraceURIError extends StackTraceError {
125
127
  constructor(message: string);
126
128
  }
127
129
 
128
- export { CErrorName, CEvent, CEventNameError, StackTraceAssertionError, StackTraceError, StackTraceEvalError, StackTraceGeneralError, StackTraceOpenSSLError, StackTraceRangeError, StackTraceReferenceError, StackTraceSyntaxError, StackTraceSystemError, StackTraceTypeError, StackTraceURIError };
130
+ declare class ServerListenEventError {
131
+ private static logger;
132
+ private static stackTrace;
133
+ /**
134
+ *
135
+ */
136
+ static hostPortUndefined(): void;
137
+ /**
138
+ *
139
+ */
140
+ static hostUndefined(): void;
141
+ /**
142
+ *
143
+ */
144
+ static portUndefined(): void;
145
+ /**
146
+ *
147
+ * @param err
148
+ */
149
+ static onEventError(err: Error): void;
150
+ /**
151
+ *
152
+ * @param error
153
+ */
154
+ static listenerError(error: Error): void;
155
+ /**
156
+ *
157
+ * @param code
158
+ */
159
+ static processBeforeExit(code: number): void;
160
+ /**
161
+ *
162
+ */
163
+ static processDisconnected(): void;
164
+ /**
165
+ *
166
+ * @param code
167
+ */
168
+ static exited(code: number): void;
169
+ /**
170
+ *
171
+ * @param promise
172
+ */
173
+ static promiseRejectionHandled(promise: Promise<any>): void;
174
+ /**
175
+ *
176
+ * @param error
177
+ */
178
+ static uncaughtException(error: any): void;
179
+ /**
180
+ *
181
+ * @param error
182
+ */
183
+ static uncaughtExceptionMonitor(error: any): void;
184
+ /**
185
+ *
186
+ * @param reason
187
+ * @param promise
188
+ */
189
+ static unhandledRejection(reason: any, promise: Promise<any>): void;
190
+ /**
191
+ *
192
+ * @param warning
193
+ */
194
+ static warning(warning: any): void;
195
+ /**
196
+ *
197
+ * @param message
198
+ */
199
+ static message(message: any): void;
200
+ /**
201
+ *
202
+ * @param type
203
+ * @param promise
204
+ * @param reason
205
+ */
206
+ static multipleResolves(type: string, promise: Promise<any>, reason: any): void;
207
+ /**
208
+ *
209
+ */
210
+ static processInterrupted(): void;
211
+ /**
212
+ *
213
+ * @param signal
214
+ */
215
+ static sigtermSignalReceived(signal: any): void;
216
+ /**
217
+ *
218
+ */
219
+ static serverClosing(): void;
220
+ /**
221
+ *
222
+ */
223
+ static dropNewConnection(): void;
224
+ /**
225
+ *
226
+ * @param errorEmitter
227
+ * @param err
228
+ * @param req
229
+ * @param res
230
+ * @param next
231
+ */
232
+ static expressErrorHandlingMiddleware(errorEmitter: EventEmitter, err: Error, req: Request, res: Response, next: NextFunction): void;
233
+ private static traceError;
234
+ }
235
+
236
+ export { CErrorName, CEvent, CEventNameError, ServerListenEventError, StackTraceAssertionError, StackTraceError, StackTraceEvalError, StackTraceGeneralError, StackTraceOpenSSLError, StackTraceRangeError, StackTraceReferenceError, StackTraceSyntaxError, StackTraceSystemError, StackTraceTypeError, StackTraceURIError };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { HttpStatusCode } from 'opticore-http-response';
2
+ import EventEmitter from 'node:events';
3
+ import { Request, Response, NextFunction } from 'opticore-express';
2
4
 
3
5
  declare const CErrorName: {
4
6
  evalError: string;
@@ -125,4 +127,110 @@ declare class StackTraceURIError extends StackTraceError {
125
127
  constructor(message: string);
126
128
  }
127
129
 
128
- export { CErrorName, CEvent, CEventNameError, StackTraceAssertionError, StackTraceError, StackTraceEvalError, StackTraceGeneralError, StackTraceOpenSSLError, StackTraceRangeError, StackTraceReferenceError, StackTraceSyntaxError, StackTraceSystemError, StackTraceTypeError, StackTraceURIError };
130
+ declare class ServerListenEventError {
131
+ private static logger;
132
+ private static stackTrace;
133
+ /**
134
+ *
135
+ */
136
+ static hostPortUndefined(): void;
137
+ /**
138
+ *
139
+ */
140
+ static hostUndefined(): void;
141
+ /**
142
+ *
143
+ */
144
+ static portUndefined(): void;
145
+ /**
146
+ *
147
+ * @param err
148
+ */
149
+ static onEventError(err: Error): void;
150
+ /**
151
+ *
152
+ * @param error
153
+ */
154
+ static listenerError(error: Error): void;
155
+ /**
156
+ *
157
+ * @param code
158
+ */
159
+ static processBeforeExit(code: number): void;
160
+ /**
161
+ *
162
+ */
163
+ static processDisconnected(): void;
164
+ /**
165
+ *
166
+ * @param code
167
+ */
168
+ static exited(code: number): void;
169
+ /**
170
+ *
171
+ * @param promise
172
+ */
173
+ static promiseRejectionHandled(promise: Promise<any>): void;
174
+ /**
175
+ *
176
+ * @param error
177
+ */
178
+ static uncaughtException(error: any): void;
179
+ /**
180
+ *
181
+ * @param error
182
+ */
183
+ static uncaughtExceptionMonitor(error: any): void;
184
+ /**
185
+ *
186
+ * @param reason
187
+ * @param promise
188
+ */
189
+ static unhandledRejection(reason: any, promise: Promise<any>): void;
190
+ /**
191
+ *
192
+ * @param warning
193
+ */
194
+ static warning(warning: any): void;
195
+ /**
196
+ *
197
+ * @param message
198
+ */
199
+ static message(message: any): void;
200
+ /**
201
+ *
202
+ * @param type
203
+ * @param promise
204
+ * @param reason
205
+ */
206
+ static multipleResolves(type: string, promise: Promise<any>, reason: any): void;
207
+ /**
208
+ *
209
+ */
210
+ static processInterrupted(): void;
211
+ /**
212
+ *
213
+ * @param signal
214
+ */
215
+ static sigtermSignalReceived(signal: any): void;
216
+ /**
217
+ *
218
+ */
219
+ static serverClosing(): void;
220
+ /**
221
+ *
222
+ */
223
+ static dropNewConnection(): void;
224
+ /**
225
+ *
226
+ * @param errorEmitter
227
+ * @param err
228
+ * @param req
229
+ * @param res
230
+ * @param next
231
+ */
232
+ static expressErrorHandlingMiddleware(errorEmitter: EventEmitter, err: Error, req: Request, res: Response, next: NextFunction): void;
233
+ private static traceError;
234
+ }
235
+
236
+ export { CErrorName, CEvent, CEventNameError, ServerListenEventError, StackTraceAssertionError, StackTraceError, StackTraceEvalError, StackTraceGeneralError, StackTraceOpenSSLError, StackTraceRangeError, StackTraceReferenceError, StackTraceSyntaxError, StackTraceSystemError, StackTraceTypeError, StackTraceURIError };
package/dist/index.js CHANGED
@@ -138,10 +138,531 @@ var StackTraceURIError = class extends StackTraceError {
138
138
  super(message, CErrorName.evalError, status10.BAD_REQUEST, true);
139
139
  }
140
140
  };
141
+
142
+ // src/core/errors/events/serverListen.event.error.ts
143
+ import process from "process";
144
+ import colors from "ansi-colors";
145
+ import chalk from "chalk";
146
+ import { LoggerCore } from "opticore-logger";
147
+ import { HttpStatusCode as status11 } from "opticore-http-response";
148
+ import { CLocal, TranslationLoader } from "opticore-translator";
149
+
150
+ // src/utils/dateTimeFormatted.utils.ts
151
+ var dateTimeFormatted = `${(/* @__PURE__ */ new Date()).getMonth()}-${(/* @__PURE__ */ new Date()).getDate()}-${(/* @__PURE__ */ new Date()).getFullYear()} ${(/* @__PURE__ */ new Date()).getHours()}:${(/* @__PURE__ */ new Date()).getMinutes()}:${(/* @__PURE__ */ new Date()).getSeconds()}`;
152
+
153
+ // src/core/errors/events/serverListen.event.error.ts
154
+ var ServerListenEventError = class {
155
+ /**
156
+ *
157
+ */
158
+ static hostPortUndefined() {
159
+ this.stackTrace = this.traceError(
160
+ TranslationLoader.t("errorHostUrl", CLocal),
161
+ TranslationLoader.t("listening", CLocal),
162
+ status11.BAD_REQUEST
163
+ );
164
+ this.logger.error(
165
+ this.stackTrace.message,
166
+ TranslationLoader.t("webServer", CLocal),
167
+ TranslationLoader.t("badHost", CLocal),
168
+ this.stackTrace.stack,
169
+ status11.BAD_REQUEST
170
+ );
171
+ process.exit();
172
+ }
173
+ /**
174
+ *
175
+ */
176
+ static hostUndefined() {
177
+ this.stackTrace = this.traceError(
178
+ TranslationLoader.t("badHost", CLocal),
179
+ TranslationLoader.t("listening", CLocal),
180
+ status11.BAD_REQUEST
181
+ );
182
+ this.logger.error(
183
+ this.stackTrace.message,
184
+ TranslationLoader.t("webServer", CLocal),
185
+ TranslationLoader.t("badHost", CLocal),
186
+ this.stackTrace.stack,
187
+ status11.BAD_REQUEST
188
+ );
189
+ process.exit();
190
+ }
191
+ /**
192
+ *
193
+ */
194
+ static portUndefined() {
195
+ this.stackTrace = this.traceError(
196
+ TranslationLoader.t("badPort", CLocal),
197
+ TranslationLoader.t("listening", CLocal),
198
+ status11.BAD_REQUEST
199
+ );
200
+ this.logger.error(
201
+ this.stackTrace.message,
202
+ TranslationLoader.t("webServer", CLocal),
203
+ TranslationLoader.t("badHost", CLocal),
204
+ this.stackTrace.stack,
205
+ status11.BAD_REQUEST
206
+ );
207
+ process.exit();
208
+ }
209
+ /**
210
+ *
211
+ * @param err
212
+ */
213
+ static onEventError(err) {
214
+ this.logger.error(
215
+ TranslationLoader.t(err.message, CLocal),
216
+ TranslationLoader.t("serverStart", CLocal),
217
+ TranslationLoader.t("serverStartError", CLocal),
218
+ err.stack,
219
+ status11.SERVICE_UNAVAILABLE
220
+ );
221
+ }
222
+ /**
223
+ *
224
+ * @param error
225
+ */
226
+ static listenerError(error) {
227
+ this.stackTrace = this.traceError(
228
+ error.message,
229
+ error.name,
230
+ status11.BAD_REQUEST
231
+ );
232
+ this.logger.error(
233
+ this.stackTrace.message,
234
+ "Event error",
235
+ "Error",
236
+ error.stack,
237
+ status11.BAD_REQUEST
238
+ );
239
+ }
240
+ /**
241
+ *
242
+ * @param code
243
+ */
244
+ static processBeforeExit(code) {
245
+ this.stackTrace = this.traceError(
246
+ TranslationLoader.t("processExitCode", CLocal, { processExitCode: code }),
247
+ TranslationLoader.t("beforeExit", CLocal),
248
+ status11.SERVICE_UNAVAILABLE
249
+ );
250
+ this.logger.error(
251
+ this.stackTrace.message,
252
+ TranslationLoader.t("beforeExit", CLocal),
253
+ TranslationLoader.t("processBeforeExit", CLocal),
254
+ this.stackTrace.stack,
255
+ status11.SERVICE_UNAVAILABLE
256
+ );
257
+ process.exit(code);
258
+ }
259
+ /**
260
+ *
261
+ */
262
+ static processDisconnected() {
263
+ this.stackTrace = this.traceError(
264
+ TranslationLoader.t("childProcessDiscon", CLocal),
265
+ TranslationLoader.t("processDiscon", CLocal),
266
+ status11.SERVICE_UNAVAILABLE
267
+ );
268
+ this.logger.error(
269
+ this.stackTrace.message,
270
+ TranslationLoader.t("disconnected"),
271
+ TranslationLoader.t("processDiscon"),
272
+ this.stackTrace.stack,
273
+ status11.SERVICE_UNAVAILABLE
274
+ );
275
+ process.exit();
276
+ }
277
+ /**
278
+ *
279
+ * @param code
280
+ */
281
+ static exited(code) {
282
+ switch (code) {
283
+ case 0:
284
+ this.logger.success(
285
+ TranslationLoader.t("completed", CLocal, {}),
286
+ TranslationLoader.t("finishingProcessWell", CLocal, { code })
287
+ );
288
+ console.log("");
289
+ const paddingLength = 35;
290
+ const msg0 = " ".padEnd(paddingLength, " ");
291
+ console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
292
+ console.log(`${colors.bgGreen(` ${TranslationLoader.t("serverStopped", CLocal)} `)}`);
293
+ console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
294
+ break;
295
+ case 1:
296
+ this.stackTrace = this.traceError(
297
+ TranslationLoader.t("somethingWentWrong", CLocal),
298
+ TranslationLoader.t("genErrors", CLocal),
299
+ status11.SERVICE_UNAVAILABLE
300
+ );
301
+ this.logger.error(
302
+ this.stackTrace.message,
303
+ TranslationLoader.t("exited", CLocal),
304
+ "General Errors",
305
+ this.stackTrace.stack,
306
+ status11.SERVICE_UNAVAILABLE
307
+ );
308
+ break;
309
+ case 2:
310
+ this.stackTrace = this.traceError(
311
+ TranslationLoader.t("incorrectCmd", CLocal),
312
+ TranslationLoader.t("misuseShell", CLocal),
313
+ status11.SERVICE_UNAVAILABLE
314
+ );
315
+ this.logger.error(
316
+ this.stackTrace.message,
317
+ TranslationLoader.t("exited", CLocal),
318
+ TranslationLoader.t("incorrectCmd", CLocal),
319
+ this.stackTrace.stack,
320
+ status11.SERVICE_UNAVAILABLE
321
+ );
322
+ break;
323
+ case 126:
324
+ this.stackTrace = this.traceError(
325
+ TranslationLoader.t("incorrectCmd", CLocal),
326
+ TranslationLoader.t("cmdNotExecutable", CLocal),
327
+ status11.SERVICE_UNAVAILABLE
328
+ );
329
+ this.logger.error(
330
+ this.stackTrace.message,
331
+ TranslationLoader.t("exited", CLocal),
332
+ this.stackTrace.name,
333
+ this.stackTrace.stack,
334
+ status11.SERVICE_UNAVAILABLE
335
+ );
336
+ break;
337
+ case 127:
338
+ this.stackTrace = this.traceError(
339
+ TranslationLoader.t("cmdNotFound", CLocal),
340
+ TranslationLoader.t("cmdNotFoundInSystemPath", CLocal),
341
+ status11.SERVICE_UNAVAILABLE
342
+ );
343
+ this.logger.error(
344
+ this.stackTrace.message,
345
+ TranslationLoader.t("exited", CLocal),
346
+ this.stackTrace.name,
347
+ this.stackTrace.stack,
348
+ status11.SERVICE_UNAVAILABLE
349
+ );
350
+ break;
351
+ case 128:
352
+ this.stackTrace = this.traceError(
353
+ TranslationLoader.t("cmdNotFoundInSystemPath", CLocal),
354
+ TranslationLoader.t("argInvalid", CLocal),
355
+ status11.SERVICE_UNAVAILABLE
356
+ );
357
+ this.logger.error(
358
+ this.stackTrace.message,
359
+ TranslationLoader.t("exited", CLocal),
360
+ this.stackTrace.name,
361
+ this.stackTrace.stack,
362
+ status11.SERVICE_UNAVAILABLE
363
+ );
364
+ break;
365
+ case 130:
366
+ this.stackTrace = this.traceError(
367
+ TranslationLoader.t("scriptEndedManuallyByCtrlC", CLocal),
368
+ TranslationLoader.t("scriptEnded", CLocal),
369
+ status11.SERVICE_UNAVAILABLE
370
+ );
371
+ this.logger.error(
372
+ this.stackTrace.message,
373
+ TranslationLoader.t("exited", CLocal),
374
+ this.stackTrace.name,
375
+ this.stackTrace.stack,
376
+ status11.SERVICE_UNAVAILABLE
377
+ );
378
+ break;
379
+ case 137:
380
+ this.stackTrace = this.traceError(
381
+ TranslationLoader.t("processEndedBySIGKILL", CLocal),
382
+ "SIGKILL",
383
+ status11.SERVICE_UNAVAILABLE
384
+ );
385
+ this.logger.error(
386
+ this.stackTrace.message,
387
+ TranslationLoader.t("exited", CLocal),
388
+ this.stackTrace.name,
389
+ this.stackTrace.stack,
390
+ status11.SERVICE_UNAVAILABLE
391
+ );
392
+ break;
393
+ case 139:
394
+ this.stackTrace = this.traceError(
395
+ TranslationLoader.t("accessProcessIllegally", CLocal),
396
+ TranslationLoader.t("defaultSegment", CLocal),
397
+ status11.SERVICE_UNAVAILABLE
398
+ );
399
+ this.logger.error(
400
+ this.stackTrace.message,
401
+ TranslationLoader.t("exited", CLocal),
402
+ this.stackTrace.name,
403
+ this.stackTrace.stack,
404
+ status11.SERVICE_UNAVAILABLE
405
+ );
406
+ break;
407
+ case 143:
408
+ this.stackTrace = this.traceError(
409
+ TranslationLoader.t("processReceivedSigtermSignal", CLocal),
410
+ TranslationLoader.t("processReceived", CLocal),
411
+ status11.SERVICE_UNAVAILABLE
412
+ );
413
+ this.logger.error(
414
+ this.stackTrace.message,
415
+ TranslationLoader.t("exited", CLocal),
416
+ this.stackTrace.name,
417
+ this.stackTrace.stack,
418
+ status11.SERVICE_UNAVAILABLE
419
+ );
420
+ break;
421
+ case 255:
422
+ this.stackTrace = this.traceError(
423
+ TranslationLoader.t("exitCode", CLocal),
424
+ TranslationLoader.t("outRange", CLocal),
425
+ status11.SERVICE_UNAVAILABLE
426
+ );
427
+ this.logger.error(
428
+ this.stackTrace.message,
429
+ TranslationLoader.t("exited", CLocal),
430
+ this.stackTrace.name,
431
+ this.stackTrace.stack,
432
+ status11.SERVICE_UNAVAILABLE
433
+ );
434
+ break;
435
+ default:
436
+ this.stackTrace = this.traceError(
437
+ TranslationLoader.t("errorOccurring", CLocal),
438
+ TranslationLoader.t("errors", CLocal),
439
+ status11.SERVICE_UNAVAILABLE
440
+ );
441
+ this.logger.error(
442
+ this.stackTrace.message,
443
+ TranslationLoader.t("exited", CLocal),
444
+ this.stackTrace.name,
445
+ this.stackTrace.stack,
446
+ status11.SERVICE_UNAVAILABLE
447
+ );
448
+ break;
449
+ }
450
+ }
451
+ /**
452
+ *
453
+ * @param promise
454
+ */
455
+ static promiseRejectionHandled(promise) {
456
+ try {
457
+ this.stackTrace = this.traceError(
458
+ TranslationLoader.t("promise", CLocal, { promise }),
459
+ TranslationLoader.t("rejectionPromise", CLocal),
460
+ status11.SERVICE_UNAVAILABLE
461
+ );
462
+ this.logger.error(
463
+ this.stackTrace.message,
464
+ "PromiseRejectionHandled",
465
+ this.stackTrace.name,
466
+ this.stackTrace.stack,
467
+ status11.SERVICE_UNAVAILABLE
468
+ );
469
+ } catch (err) {
470
+ }
471
+ }
472
+ /**
473
+ *
474
+ * @param error
475
+ */
476
+ static uncaughtException(error) {
477
+ 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.") {
478
+ console.log("");
479
+ } else {
480
+ this.stackTrace = this.traceError(
481
+ TranslationLoader.t(error.message),
482
+ TranslationLoader.t("uncaughtExceptionHandled", CLocal),
483
+ status11.SERVICE_UNAVAILABLE
484
+ );
485
+ this.logger.error(
486
+ this.stackTrace.message,
487
+ "UncaughtException",
488
+ this.stackTrace.name,
489
+ this.stackTrace.stack,
490
+ status11.SERVICE_UNAVAILABLE
491
+ );
492
+ }
493
+ }
494
+ /**
495
+ *
496
+ * @param error
497
+ */
498
+ static uncaughtExceptionMonitor(error) {
499
+ 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.") {
500
+ console.log("");
501
+ }
502
+ }
503
+ /**
504
+ *
505
+ * @param reason
506
+ * @param promise
507
+ */
508
+ static unhandledRejection(reason, promise) {
509
+ this.stackTrace = this.traceError(
510
+ TranslationLoader.t("unhandledRejectionAtPromise", CLocal, { promise, reason }),
511
+ TranslationLoader.t("unhandledRejection", CLocal),
512
+ status11.SERVICE_UNAVAILABLE
513
+ );
514
+ this.logger.error(
515
+ this.stackTrace.message,
516
+ "UnhandledRejection",
517
+ this.stackTrace.name,
518
+ this.stackTrace.stack,
519
+ status11.SERVICE_UNAVAILABLE
520
+ );
521
+ }
522
+ /**
523
+ *
524
+ * @param warning
525
+ */
526
+ static warning(warning) {
527
+ this.stackTrace = this.traceError(
528
+ TranslationLoader.t(warning.message, CLocal),
529
+ "warning",
530
+ status11.SERVICE_UNAVAILABLE
531
+ );
532
+ this.logger.error(
533
+ this.stackTrace.message,
534
+ TranslationLoader.t("warning", CLocal),
535
+ this.stackTrace.name,
536
+ this.stackTrace.stack,
537
+ status11.SERVICE_UNAVAILABLE
538
+ );
539
+ }
540
+ /**
541
+ *
542
+ * @param message
543
+ */
544
+ static message(message) {
545
+ this.stackTrace = this.traceError(
546
+ TranslationLoader.t("processGotMsg", CLocal, { message }),
547
+ TranslationLoader.t("msgException", CLocal),
548
+ status11.SERVICE_UNAVAILABLE
549
+ );
550
+ this.logger.error(
551
+ this.stackTrace.message,
552
+ "Message",
553
+ this.stackTrace.name,
554
+ this.stackTrace.stack,
555
+ status11.SERVICE_UNAVAILABLE
556
+ );
557
+ }
558
+ /**
559
+ *
560
+ * @param type
561
+ * @param promise
562
+ * @param reason
563
+ */
564
+ static multipleResolves(type, promise, reason) {
565
+ this.stackTrace = this.traceError(
566
+ TranslationLoader.t("promiseReason", CLocal, { promise, reason }),
567
+ TranslationLoader.t("multipleResolvesDetected", CLocal, { type }),
568
+ status11.SERVICE_UNAVAILABLE
569
+ );
570
+ this.logger.error(
571
+ this.stackTrace.message,
572
+ "multipleResolves",
573
+ this.stackTrace.name,
574
+ this.stackTrace.stack,
575
+ status11.SERVICE_UNAVAILABLE
576
+ );
577
+ }
578
+ /**
579
+ *
580
+ */
581
+ static processInterrupted() {
582
+ this.logger.success(TranslationLoader.t("okSuccess", CLocal), TranslationLoader.t("serverWebStopped", CLocal));
583
+ process.exit(0);
584
+ }
585
+ /**
586
+ *
587
+ * @param signal
588
+ */
589
+ static sigtermSignalReceived(signal) {
590
+ this.stackTrace = this.traceError(
591
+ TranslationLoader.t("processPIDReceivedSignal", CLocal, { signal: signal.toString() }),
592
+ "SIGTERM",
593
+ status11.NOT_ACCEPTABLE
594
+ );
595
+ this.logger.error(
596
+ this.stackTrace.message,
597
+ "SIGTERM",
598
+ this.stackTrace.name,
599
+ this.stackTrace.stack,
600
+ status11.NOT_ACCEPTABLE
601
+ );
602
+ process.exit(0);
603
+ }
604
+ /**
605
+ *
606
+ */
607
+ static serverClosing() {
608
+ console.log(`${colors.bgCyanBright(` ${colors.bold(`${colors.white(` INFO `)}`)}`)} ${TranslationLoader.t("allProcessStopped", CLocal)}`);
609
+ console.log(` ${TranslationLoader.t("serverClosed", CLocal)}`);
610
+ process.exit();
611
+ }
612
+ /**
613
+ *
614
+ */
615
+ static dropNewConnection() {
616
+ console.log(`${colors.cyan(`\u24D8`)} ${colors.bgCyan(` ${colors.bold(`${colors.white(` ${TranslationLoader.t("serverMaxCon", CLocal)} `)}`)} `)} ${dateTimeFormatted} | ${colors.bgCyan(`${colors.white(` Info `)}`)} ${TranslationLoader.t("serverDroppedCon", CLocal)}`);
617
+ }
618
+ /**
619
+ *
620
+ * @param errorEmitter
621
+ * @param err
622
+ * @param req
623
+ * @param res
624
+ * @param next
625
+ */
626
+ static expressErrorHandlingMiddleware(errorEmitter, err, req, res, next) {
627
+ if (err) {
628
+ errorEmitter.emit(CEventNameError.error, err);
629
+ if (typeof res.status === "function") {
630
+ res.status(500).send(TranslationLoader.t("internalServerError", CLocal, { err }));
631
+ } else {
632
+ this.logger.error(
633
+ TranslationLoader.t("resStatusNotFunc", CLocal, { err }),
634
+ "response status",
635
+ TranslationLoader.t("respndNotFunc", CLocal, { err }),
636
+ err.stack,
637
+ status11.NOT_ACCEPTABLE
638
+ );
639
+ }
640
+ this.stackTrace = this.traceError(
641
+ err.message,
642
+ TranslationLoader.t("expressError", CLocal, { err }),
643
+ status11.NOT_ACCEPTABLE
644
+ );
645
+ this.logger.error(
646
+ this.stackTrace.message,
647
+ TranslationLoader.t("expressErrorHandlingMiddleware", CLocal, { err }),
648
+ this.stackTrace.name,
649
+ this.stackTrace.stack,
650
+ status11.SERVICE_UNAVAILABLE
651
+ );
652
+ } else {
653
+ next();
654
+ }
655
+ }
656
+ static traceError(props, name, status12) {
657
+ return new StackTraceError(props, name, status12, true);
658
+ }
659
+ };
660
+ ServerListenEventError.logger = new LoggerCore();
141
661
  export {
142
662
  CErrorName,
143
663
  CEvent,
144
664
  CEventNameError,
665
+ ServerListenEventError,
145
666
  StackTraceAssertionError,
146
667
  StackTraceError,
147
668
  StackTraceEvalError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opticore-catch-exception-error",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "opticore catch exception error",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -25,13 +25,17 @@
25
25
  },
26
26
  "homepage": "https://github.com/guyzoum77/opticore-catch-exception-error#readme",
27
27
  "dependencies": {
28
- "opticore-http-response": "^1.0.3"
28
+ "chalk": "^5.4.1",
29
+ "node": "^22.13.5",
30
+ "opticore-express": "^1.0.1",
31
+ "opticore-http-response": "^1.0.3",
32
+ "opticore-translator": "^1.0.1"
29
33
  },
30
34
  "devDependencies": {
31
35
  "@types/node": "^22.13.5",
32
36
  "reflect-metadata": "^0.2.2",
33
37
  "tslib": "^2.8.1",
34
- "typescript": "^5.4.5",
35
- "tsup": "^8.4.0"
38
+ "tsup": "^8.4.0",
39
+ "typescript": "^5.4.5"
36
40
  }
37
41
  }