opticore-catch-exception-error 1.0.0 → 1.0.1

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,523 @@ 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(import_opticore_translator.TranslationLoader.t("completed", import_opticore_translator.CLocal), import_opticore_translator.TranslationLoader.t("finishingProcessWell", import_opticore_translator.CLocal));
335
+ console.log("");
336
+ const paddingLength = 35;
337
+ const msg0 = " ".padEnd(paddingLength, " ");
338
+ console.log(import_chalk.default.bgGreen.white(msg0.padEnd(paddingLength, " ")));
339
+ console.log(`${import_ansi_colors.default.bgGreen(` ${import_opticore_translator.TranslationLoader.t("serverStopped", import_opticore_translator.CLocal)} `)}`);
340
+ console.log(import_chalk.default.bgGreen.white(msg0.padEnd(paddingLength, " ")));
341
+ break;
342
+ case 1:
343
+ this.stackTrace = this.traceError(
344
+ import_opticore_translator.TranslationLoader.t("somethingWentWrong", import_opticore_translator.CLocal),
345
+ import_opticore_translator.TranslationLoader.t("genErrors", import_opticore_translator.CLocal),
346
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
347
+ );
348
+ this.logger.error(
349
+ this.stackTrace.message,
350
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
351
+ "General Errors",
352
+ this.stackTrace.stack,
353
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
354
+ );
355
+ break;
356
+ case 2:
357
+ this.stackTrace = this.traceError(
358
+ import_opticore_translator.TranslationLoader.t("incorrectCmd", import_opticore_translator.CLocal),
359
+ import_opticore_translator.TranslationLoader.t("misuseShell", import_opticore_translator.CLocal),
360
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
361
+ );
362
+ this.logger.error(
363
+ this.stackTrace.message,
364
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
365
+ import_opticore_translator.TranslationLoader.t("incorrectCmd", import_opticore_translator.CLocal),
366
+ this.stackTrace.stack,
367
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
368
+ );
369
+ break;
370
+ case 126:
371
+ this.stackTrace = this.traceError(
372
+ import_opticore_translator.TranslationLoader.t("incorrectCmd", import_opticore_translator.CLocal),
373
+ import_opticore_translator.TranslationLoader.t("cmdNotExecutable", import_opticore_translator.CLocal),
374
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
375
+ );
376
+ this.logger.error(
377
+ this.stackTrace.message,
378
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
379
+ this.stackTrace.name,
380
+ this.stackTrace.stack,
381
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
382
+ );
383
+ break;
384
+ case 127:
385
+ this.stackTrace = this.traceError(
386
+ import_opticore_translator.TranslationLoader.t("cmdNotFound", import_opticore_translator.CLocal),
387
+ import_opticore_translator.TranslationLoader.t("cmdNotFoundInSystemPath", import_opticore_translator.CLocal),
388
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
389
+ );
390
+ this.logger.error(
391
+ this.stackTrace.message,
392
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
393
+ this.stackTrace.name,
394
+ this.stackTrace.stack,
395
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
396
+ );
397
+ break;
398
+ case 128:
399
+ this.stackTrace = this.traceError(
400
+ import_opticore_translator.TranslationLoader.t("cmdNotFoundInSystemPath", import_opticore_translator.CLocal),
401
+ import_opticore_translator.TranslationLoader.t("argInvalid", import_opticore_translator.CLocal),
402
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
403
+ );
404
+ this.logger.error(
405
+ this.stackTrace.message,
406
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
407
+ this.stackTrace.name,
408
+ this.stackTrace.stack,
409
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
410
+ );
411
+ break;
412
+ case 130:
413
+ this.stackTrace = this.traceError(
414
+ import_opticore_translator.TranslationLoader.t("scriptEndedManuallyByCtrlC", import_opticore_translator.CLocal),
415
+ import_opticore_translator.TranslationLoader.t("scriptEnded", import_opticore_translator.CLocal),
416
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
417
+ );
418
+ this.logger.error(
419
+ this.stackTrace.message,
420
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
421
+ this.stackTrace.name,
422
+ this.stackTrace.stack,
423
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
424
+ );
425
+ break;
426
+ case 137:
427
+ this.stackTrace = this.traceError(
428
+ import_opticore_translator.TranslationLoader.t("processEndedBySIGKILL", import_opticore_translator.CLocal),
429
+ "SIGKILL",
430
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
431
+ );
432
+ this.logger.error(
433
+ this.stackTrace.message,
434
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
435
+ this.stackTrace.name,
436
+ this.stackTrace.stack,
437
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
438
+ );
439
+ break;
440
+ case 139:
441
+ this.stackTrace = this.traceError(
442
+ import_opticore_translator.TranslationLoader.t("accessProcessIllegally", import_opticore_translator.CLocal),
443
+ import_opticore_translator.TranslationLoader.t("defaultSegment", import_opticore_translator.CLocal),
444
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
445
+ );
446
+ this.logger.error(
447
+ this.stackTrace.message,
448
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
449
+ this.stackTrace.name,
450
+ this.stackTrace.stack,
451
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
452
+ );
453
+ break;
454
+ case 143:
455
+ this.stackTrace = this.traceError(
456
+ import_opticore_translator.TranslationLoader.t("processReceivedSigtermSignal", import_opticore_translator.CLocal),
457
+ import_opticore_translator.TranslationLoader.t("processReceived", import_opticore_translator.CLocal),
458
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
459
+ );
460
+ this.logger.error(
461
+ this.stackTrace.message,
462
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
463
+ this.stackTrace.name,
464
+ this.stackTrace.stack,
465
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
466
+ );
467
+ break;
468
+ case 255:
469
+ this.stackTrace = this.traceError(
470
+ import_opticore_translator.TranslationLoader.t("exitCode", import_opticore_translator.CLocal),
471
+ import_opticore_translator.TranslationLoader.t("outRange", import_opticore_translator.CLocal),
472
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
473
+ );
474
+ this.logger.error(
475
+ this.stackTrace.message,
476
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
477
+ this.stackTrace.name,
478
+ this.stackTrace.stack,
479
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
480
+ );
481
+ break;
482
+ default:
483
+ this.stackTrace = this.traceError(
484
+ import_opticore_translator.TranslationLoader.t("errorOccurring", import_opticore_translator.CLocal),
485
+ import_opticore_translator.TranslationLoader.t("errors", import_opticore_translator.CLocal),
486
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
487
+ );
488
+ this.logger.error(
489
+ this.stackTrace.message,
490
+ import_opticore_translator.TranslationLoader.t("exited", import_opticore_translator.CLocal),
491
+ this.stackTrace.name,
492
+ this.stackTrace.stack,
493
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
494
+ );
495
+ break;
496
+ }
497
+ }
498
+ /**
499
+ *
500
+ * @param promise
501
+ */
502
+ static promiseRejectionHandled(promise) {
503
+ this.stackTrace = this.traceError(
504
+ import_opticore_translator.TranslationLoader.t("promise", import_opticore_translator.CLocal, { promise }),
505
+ import_opticore_translator.TranslationLoader.t("rejectionPromise", import_opticore_translator.CLocal),
506
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
507
+ );
508
+ this.logger.error(
509
+ this.stackTrace.message,
510
+ "PromiseRejectionHandled",
511
+ this.stackTrace.name,
512
+ this.stackTrace.stack,
513
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
514
+ );
515
+ }
516
+ /**
517
+ *
518
+ * @param error
519
+ */
520
+ static uncaughtException(error) {
521
+ 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.") {
522
+ console.log("");
523
+ } else {
524
+ this.stackTrace = this.traceError(
525
+ import_opticore_translator.TranslationLoader.t(error.message),
526
+ import_opticore_translator.TranslationLoader.t("uncaughtExceptionHandled", import_opticore_translator.CLocal),
527
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
528
+ );
529
+ this.logger.error(
530
+ this.stackTrace.message,
531
+ "UncaughtException",
532
+ this.stackTrace.name,
533
+ this.stackTrace.stack,
534
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
535
+ );
536
+ }
537
+ }
538
+ /**
539
+ *
540
+ * @param error
541
+ */
542
+ static uncaughtExceptionMonitor(error) {
543
+ 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.") {
544
+ console.log("");
545
+ }
546
+ }
547
+ /**
548
+ *
549
+ * @param reason
550
+ * @param promise
551
+ */
552
+ static unhandledRejection(reason, promise) {
553
+ this.stackTrace = this.traceError(
554
+ import_opticore_translator.TranslationLoader.t("unhandledRejectionAtPromise", import_opticore_translator.CLocal),
555
+ import_opticore_translator.TranslationLoader.t("unhandledRejection", import_opticore_translator.CLocal),
556
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
557
+ );
558
+ this.logger.error(
559
+ this.stackTrace.message,
560
+ "UnhandledRejection",
561
+ this.stackTrace.name,
562
+ this.stackTrace.stack,
563
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
564
+ );
565
+ }
566
+ /**
567
+ *
568
+ * @param warning
569
+ */
570
+ static warning(warning) {
571
+ this.stackTrace = this.traceError(
572
+ import_opticore_translator.TranslationLoader.t(warning.message, import_opticore_translator.CLocal),
573
+ "warning",
574
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
575
+ );
576
+ this.logger.error(
577
+ this.stackTrace.message,
578
+ import_opticore_translator.TranslationLoader.t("Warning", import_opticore_translator.CLocal),
579
+ this.stackTrace.name,
580
+ this.stackTrace.stack,
581
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
582
+ );
583
+ }
584
+ /**
585
+ *
586
+ * @param message
587
+ */
588
+ static message(message) {
589
+ this.stackTrace = this.traceError(
590
+ import_opticore_translator.TranslationLoader.t("processGotMsg", import_opticore_translator.CLocal, { message }),
591
+ import_opticore_translator.TranslationLoader.t("msgException", import_opticore_translator.CLocal),
592
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
593
+ );
594
+ this.logger.error(
595
+ this.stackTrace.message,
596
+ "Message",
597
+ this.stackTrace.name,
598
+ this.stackTrace.stack,
599
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
600
+ );
601
+ }
602
+ /**
603
+ *
604
+ * @param type
605
+ * @param promise
606
+ * @param reason
607
+ */
608
+ static multipleResolves(type, promise, reason) {
609
+ this.stackTrace = this.traceError(
610
+ import_opticore_translator.TranslationLoader.t("promiseReason", import_opticore_translator.CLocal, { promise, reason }),
611
+ import_opticore_translator.TranslationLoader.t("multipleResolvesDetected", import_opticore_translator.CLocal, { type }),
612
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
613
+ );
614
+ this.logger.error(
615
+ this.stackTrace.message,
616
+ "multipleResolves",
617
+ this.stackTrace.name,
618
+ this.stackTrace.stack,
619
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
620
+ );
621
+ }
622
+ /**
623
+ *
624
+ */
625
+ static processInterrupted() {
626
+ this.logger.success(import_opticore_translator.TranslationLoader.t("okSuccess", import_opticore_translator.CLocal), import_opticore_translator.TranslationLoader.t("serverWebStopped", import_opticore_translator.CLocal));
627
+ import_process.default.exit(0);
628
+ }
629
+ /**
630
+ *
631
+ * @param signal
632
+ */
633
+ static sigtermSignalReceived(signal) {
634
+ this.stackTrace = this.traceError(
635
+ import_opticore_translator.TranslationLoader.t("processPIDReceivedSignal", import_opticore_translator.CLocal, { signal: signal.toString() }),
636
+ "SIGTERM",
637
+ import_opticore_http_response11.HttpStatusCode.NOT_ACCEPTABLE
638
+ );
639
+ this.logger.error(
640
+ this.stackTrace.message,
641
+ "SIGTERM",
642
+ this.stackTrace.name,
643
+ this.stackTrace.stack,
644
+ import_opticore_http_response11.HttpStatusCode.NOT_ACCEPTABLE
645
+ );
646
+ import_process.default.exit(0);
647
+ }
648
+ /**
649
+ *
650
+ */
651
+ static serverClosing() {
652
+ 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)}`);
653
+ console.log(` ${import_opticore_translator.TranslationLoader.t("serverClosed", import_opticore_translator.CLocal)}`);
654
+ import_process.default.exit();
655
+ }
656
+ /**
657
+ *
658
+ */
659
+ static dropNewConnection() {
660
+ 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)}`);
661
+ }
662
+ /**
663
+ *
664
+ * @param errorEmitter
665
+ * @param err
666
+ * @param req
667
+ * @param res
668
+ * @param next
669
+ */
670
+ static expressErrorHandlingMiddleware(errorEmitter, err, req, res, next) {
671
+ if (err) {
672
+ errorEmitter.emit(CEventNameError.error, err);
673
+ if (typeof res.status === "function") {
674
+ res.status(500).send(import_opticore_translator.TranslationLoader.t("internalServerError", import_opticore_translator.CLocal));
675
+ } else {
676
+ console.error("res.status is not a function");
677
+ this.logger.error(
678
+ import_opticore_translator.TranslationLoader.t("resStatusNotFunc", import_opticore_translator.CLocal),
679
+ "response status",
680
+ import_opticore_translator.TranslationLoader.t("respndNotFunc", import_opticore_translator.CLocal),
681
+ err.stack,
682
+ import_opticore_http_response11.HttpStatusCode.NOT_ACCEPTABLE
683
+ );
684
+ }
685
+ this.stackTrace = this.traceError(err.message, import_opticore_translator.TranslationLoader.t("expressError", import_opticore_translator.CLocal), import_opticore_http_response11.HttpStatusCode.NOT_ACCEPTABLE);
686
+ this.logger.error(
687
+ this.stackTrace.message,
688
+ import_opticore_translator.TranslationLoader.t("expressErrorHandlingMiddleware", import_opticore_translator.CLocal),
689
+ this.stackTrace.name,
690
+ this.stackTrace.stack,
691
+ import_opticore_http_response11.HttpStatusCode.SERVICE_UNAVAILABLE
692
+ );
693
+ } else {
694
+ next();
695
+ }
696
+ }
697
+ static traceError(props, name, status12) {
698
+ return new StackTraceError(props, name, status12, true);
699
+ }
700
+ };
701
+ ServerListenEventError.logger = new import_opticore_logger.LoggerCore();
180
702
  // Annotate the CommonJS export names for ESM import in node:
181
703
  0 && (module.exports = {
182
704
  CErrorName,
183
705
  CEvent,
184
706
  CEventNameError,
707
+ ServerListenEventError,
185
708
  StackTraceAssertionError,
186
709
  StackTraceError,
187
710
  StackTraceEvalError,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,6 @@
1
1
  import { HttpStatusCode } from 'opticore-http-response';
2
+ import { Request, Response, NextFunction } from 'opticore-express';
3
+ import EventEmitter from 'node:events';
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 { Request, Response, NextFunction } from 'opticore-express';
3
+ import EventEmitter from 'node:events';
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,522 @@ 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(TranslationLoader.t("completed", CLocal), TranslationLoader.t("finishingProcessWell", CLocal));
285
+ console.log("");
286
+ const paddingLength = 35;
287
+ const msg0 = " ".padEnd(paddingLength, " ");
288
+ console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
289
+ console.log(`${colors.bgGreen(` ${TranslationLoader.t("serverStopped", CLocal)} `)}`);
290
+ console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
291
+ break;
292
+ case 1:
293
+ this.stackTrace = this.traceError(
294
+ TranslationLoader.t("somethingWentWrong", CLocal),
295
+ TranslationLoader.t("genErrors", CLocal),
296
+ status11.SERVICE_UNAVAILABLE
297
+ );
298
+ this.logger.error(
299
+ this.stackTrace.message,
300
+ TranslationLoader.t("exited", CLocal),
301
+ "General Errors",
302
+ this.stackTrace.stack,
303
+ status11.SERVICE_UNAVAILABLE
304
+ );
305
+ break;
306
+ case 2:
307
+ this.stackTrace = this.traceError(
308
+ TranslationLoader.t("incorrectCmd", CLocal),
309
+ TranslationLoader.t("misuseShell", CLocal),
310
+ status11.SERVICE_UNAVAILABLE
311
+ );
312
+ this.logger.error(
313
+ this.stackTrace.message,
314
+ TranslationLoader.t("exited", CLocal),
315
+ TranslationLoader.t("incorrectCmd", CLocal),
316
+ this.stackTrace.stack,
317
+ status11.SERVICE_UNAVAILABLE
318
+ );
319
+ break;
320
+ case 126:
321
+ this.stackTrace = this.traceError(
322
+ TranslationLoader.t("incorrectCmd", CLocal),
323
+ TranslationLoader.t("cmdNotExecutable", CLocal),
324
+ status11.SERVICE_UNAVAILABLE
325
+ );
326
+ this.logger.error(
327
+ this.stackTrace.message,
328
+ TranslationLoader.t("exited", CLocal),
329
+ this.stackTrace.name,
330
+ this.stackTrace.stack,
331
+ status11.SERVICE_UNAVAILABLE
332
+ );
333
+ break;
334
+ case 127:
335
+ this.stackTrace = this.traceError(
336
+ TranslationLoader.t("cmdNotFound", CLocal),
337
+ TranslationLoader.t("cmdNotFoundInSystemPath", CLocal),
338
+ status11.SERVICE_UNAVAILABLE
339
+ );
340
+ this.logger.error(
341
+ this.stackTrace.message,
342
+ TranslationLoader.t("exited", CLocal),
343
+ this.stackTrace.name,
344
+ this.stackTrace.stack,
345
+ status11.SERVICE_UNAVAILABLE
346
+ );
347
+ break;
348
+ case 128:
349
+ this.stackTrace = this.traceError(
350
+ TranslationLoader.t("cmdNotFoundInSystemPath", CLocal),
351
+ TranslationLoader.t("argInvalid", CLocal),
352
+ status11.SERVICE_UNAVAILABLE
353
+ );
354
+ this.logger.error(
355
+ this.stackTrace.message,
356
+ TranslationLoader.t("exited", CLocal),
357
+ this.stackTrace.name,
358
+ this.stackTrace.stack,
359
+ status11.SERVICE_UNAVAILABLE
360
+ );
361
+ break;
362
+ case 130:
363
+ this.stackTrace = this.traceError(
364
+ TranslationLoader.t("scriptEndedManuallyByCtrlC", CLocal),
365
+ TranslationLoader.t("scriptEnded", CLocal),
366
+ status11.SERVICE_UNAVAILABLE
367
+ );
368
+ this.logger.error(
369
+ this.stackTrace.message,
370
+ TranslationLoader.t("exited", CLocal),
371
+ this.stackTrace.name,
372
+ this.stackTrace.stack,
373
+ status11.SERVICE_UNAVAILABLE
374
+ );
375
+ break;
376
+ case 137:
377
+ this.stackTrace = this.traceError(
378
+ TranslationLoader.t("processEndedBySIGKILL", CLocal),
379
+ "SIGKILL",
380
+ status11.SERVICE_UNAVAILABLE
381
+ );
382
+ this.logger.error(
383
+ this.stackTrace.message,
384
+ TranslationLoader.t("exited", CLocal),
385
+ this.stackTrace.name,
386
+ this.stackTrace.stack,
387
+ status11.SERVICE_UNAVAILABLE
388
+ );
389
+ break;
390
+ case 139:
391
+ this.stackTrace = this.traceError(
392
+ TranslationLoader.t("accessProcessIllegally", CLocal),
393
+ TranslationLoader.t("defaultSegment", CLocal),
394
+ status11.SERVICE_UNAVAILABLE
395
+ );
396
+ this.logger.error(
397
+ this.stackTrace.message,
398
+ TranslationLoader.t("exited", CLocal),
399
+ this.stackTrace.name,
400
+ this.stackTrace.stack,
401
+ status11.SERVICE_UNAVAILABLE
402
+ );
403
+ break;
404
+ case 143:
405
+ this.stackTrace = this.traceError(
406
+ TranslationLoader.t("processReceivedSigtermSignal", CLocal),
407
+ TranslationLoader.t("processReceived", CLocal),
408
+ status11.SERVICE_UNAVAILABLE
409
+ );
410
+ this.logger.error(
411
+ this.stackTrace.message,
412
+ TranslationLoader.t("exited", CLocal),
413
+ this.stackTrace.name,
414
+ this.stackTrace.stack,
415
+ status11.SERVICE_UNAVAILABLE
416
+ );
417
+ break;
418
+ case 255:
419
+ this.stackTrace = this.traceError(
420
+ TranslationLoader.t("exitCode", CLocal),
421
+ TranslationLoader.t("outRange", CLocal),
422
+ status11.SERVICE_UNAVAILABLE
423
+ );
424
+ this.logger.error(
425
+ this.stackTrace.message,
426
+ TranslationLoader.t("exited", CLocal),
427
+ this.stackTrace.name,
428
+ this.stackTrace.stack,
429
+ status11.SERVICE_UNAVAILABLE
430
+ );
431
+ break;
432
+ default:
433
+ this.stackTrace = this.traceError(
434
+ TranslationLoader.t("errorOccurring", CLocal),
435
+ TranslationLoader.t("errors", CLocal),
436
+ status11.SERVICE_UNAVAILABLE
437
+ );
438
+ this.logger.error(
439
+ this.stackTrace.message,
440
+ TranslationLoader.t("exited", CLocal),
441
+ this.stackTrace.name,
442
+ this.stackTrace.stack,
443
+ status11.SERVICE_UNAVAILABLE
444
+ );
445
+ break;
446
+ }
447
+ }
448
+ /**
449
+ *
450
+ * @param promise
451
+ */
452
+ static promiseRejectionHandled(promise) {
453
+ this.stackTrace = this.traceError(
454
+ TranslationLoader.t("promise", CLocal, { promise }),
455
+ TranslationLoader.t("rejectionPromise", CLocal),
456
+ status11.SERVICE_UNAVAILABLE
457
+ );
458
+ this.logger.error(
459
+ this.stackTrace.message,
460
+ "PromiseRejectionHandled",
461
+ this.stackTrace.name,
462
+ this.stackTrace.stack,
463
+ status11.SERVICE_UNAVAILABLE
464
+ );
465
+ }
466
+ /**
467
+ *
468
+ * @param error
469
+ */
470
+ static uncaughtException(error) {
471
+ 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.") {
472
+ console.log("");
473
+ } else {
474
+ this.stackTrace = this.traceError(
475
+ TranslationLoader.t(error.message),
476
+ TranslationLoader.t("uncaughtExceptionHandled", CLocal),
477
+ status11.SERVICE_UNAVAILABLE
478
+ );
479
+ this.logger.error(
480
+ this.stackTrace.message,
481
+ "UncaughtException",
482
+ this.stackTrace.name,
483
+ this.stackTrace.stack,
484
+ status11.SERVICE_UNAVAILABLE
485
+ );
486
+ }
487
+ }
488
+ /**
489
+ *
490
+ * @param error
491
+ */
492
+ static uncaughtExceptionMonitor(error) {
493
+ 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.") {
494
+ console.log("");
495
+ }
496
+ }
497
+ /**
498
+ *
499
+ * @param reason
500
+ * @param promise
501
+ */
502
+ static unhandledRejection(reason, promise) {
503
+ this.stackTrace = this.traceError(
504
+ TranslationLoader.t("unhandledRejectionAtPromise", CLocal),
505
+ TranslationLoader.t("unhandledRejection", CLocal),
506
+ status11.SERVICE_UNAVAILABLE
507
+ );
508
+ this.logger.error(
509
+ this.stackTrace.message,
510
+ "UnhandledRejection",
511
+ this.stackTrace.name,
512
+ this.stackTrace.stack,
513
+ status11.SERVICE_UNAVAILABLE
514
+ );
515
+ }
516
+ /**
517
+ *
518
+ * @param warning
519
+ */
520
+ static warning(warning) {
521
+ this.stackTrace = this.traceError(
522
+ TranslationLoader.t(warning.message, CLocal),
523
+ "warning",
524
+ status11.SERVICE_UNAVAILABLE
525
+ );
526
+ this.logger.error(
527
+ this.stackTrace.message,
528
+ TranslationLoader.t("Warning", CLocal),
529
+ this.stackTrace.name,
530
+ this.stackTrace.stack,
531
+ status11.SERVICE_UNAVAILABLE
532
+ );
533
+ }
534
+ /**
535
+ *
536
+ * @param message
537
+ */
538
+ static message(message) {
539
+ this.stackTrace = this.traceError(
540
+ TranslationLoader.t("processGotMsg", CLocal, { message }),
541
+ TranslationLoader.t("msgException", CLocal),
542
+ status11.SERVICE_UNAVAILABLE
543
+ );
544
+ this.logger.error(
545
+ this.stackTrace.message,
546
+ "Message",
547
+ this.stackTrace.name,
548
+ this.stackTrace.stack,
549
+ status11.SERVICE_UNAVAILABLE
550
+ );
551
+ }
552
+ /**
553
+ *
554
+ * @param type
555
+ * @param promise
556
+ * @param reason
557
+ */
558
+ static multipleResolves(type, promise, reason) {
559
+ this.stackTrace = this.traceError(
560
+ TranslationLoader.t("promiseReason", CLocal, { promise, reason }),
561
+ TranslationLoader.t("multipleResolvesDetected", CLocal, { type }),
562
+ status11.SERVICE_UNAVAILABLE
563
+ );
564
+ this.logger.error(
565
+ this.stackTrace.message,
566
+ "multipleResolves",
567
+ this.stackTrace.name,
568
+ this.stackTrace.stack,
569
+ status11.SERVICE_UNAVAILABLE
570
+ );
571
+ }
572
+ /**
573
+ *
574
+ */
575
+ static processInterrupted() {
576
+ this.logger.success(TranslationLoader.t("okSuccess", CLocal), TranslationLoader.t("serverWebStopped", CLocal));
577
+ process.exit(0);
578
+ }
579
+ /**
580
+ *
581
+ * @param signal
582
+ */
583
+ static sigtermSignalReceived(signal) {
584
+ this.stackTrace = this.traceError(
585
+ TranslationLoader.t("processPIDReceivedSignal", CLocal, { signal: signal.toString() }),
586
+ "SIGTERM",
587
+ status11.NOT_ACCEPTABLE
588
+ );
589
+ this.logger.error(
590
+ this.stackTrace.message,
591
+ "SIGTERM",
592
+ this.stackTrace.name,
593
+ this.stackTrace.stack,
594
+ status11.NOT_ACCEPTABLE
595
+ );
596
+ process.exit(0);
597
+ }
598
+ /**
599
+ *
600
+ */
601
+ static serverClosing() {
602
+ console.log(`${colors.bgCyanBright(` ${colors.bold(`${colors.white(` INFO `)}`)}`)} ${TranslationLoader.t("allProcessStopped", CLocal)}`);
603
+ console.log(` ${TranslationLoader.t("serverClosed", CLocal)}`);
604
+ process.exit();
605
+ }
606
+ /**
607
+ *
608
+ */
609
+ static dropNewConnection() {
610
+ 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)}`);
611
+ }
612
+ /**
613
+ *
614
+ * @param errorEmitter
615
+ * @param err
616
+ * @param req
617
+ * @param res
618
+ * @param next
619
+ */
620
+ static expressErrorHandlingMiddleware(errorEmitter, err, req, res, next) {
621
+ if (err) {
622
+ errorEmitter.emit(CEventNameError.error, err);
623
+ if (typeof res.status === "function") {
624
+ res.status(500).send(TranslationLoader.t("internalServerError", CLocal));
625
+ } else {
626
+ console.error("res.status is not a function");
627
+ this.logger.error(
628
+ TranslationLoader.t("resStatusNotFunc", CLocal),
629
+ "response status",
630
+ TranslationLoader.t("respndNotFunc", CLocal),
631
+ err.stack,
632
+ status11.NOT_ACCEPTABLE
633
+ );
634
+ }
635
+ this.stackTrace = this.traceError(err.message, TranslationLoader.t("expressError", CLocal), status11.NOT_ACCEPTABLE);
636
+ this.logger.error(
637
+ this.stackTrace.message,
638
+ TranslationLoader.t("expressErrorHandlingMiddleware", CLocal),
639
+ this.stackTrace.name,
640
+ this.stackTrace.stack,
641
+ status11.SERVICE_UNAVAILABLE
642
+ );
643
+ } else {
644
+ next();
645
+ }
646
+ }
647
+ static traceError(props, name, status12) {
648
+ return new StackTraceError(props, name, status12, true);
649
+ }
650
+ };
651
+ ServerListenEventError.logger = new LoggerCore();
141
652
  export {
142
653
  CErrorName,
143
654
  CEvent,
144
655
  CEventNameError,
656
+ ServerListenEventError,
145
657
  StackTraceAssertionError,
146
658
  StackTraceError,
147
659
  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.1",
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
  }