Align some types definition in UI
[e-mobility-charging-stations-simulator.git] / src / charging-station / Bootstrap.ts
index eb437ab08cf5e6e81baa1e8bf69499133200e456..7c80067ccd93905b2e76cec7ac9a3641bd670ff6 100644 (file)
@@ -18,7 +18,7 @@ import {
   ChargingStationWorkerMessageEvents,
 } from '../types/ChargingStationWorker';
 import type { StationTemplateUrl } from '../types/ConfigurationData';
-import type Statistics from '../types/Statistics';
+import type { Statistics } from '../types/Statistics';
 import Configuration from '../utils/Configuration';
 import logger from '../utils/Logger';
 import Utils from '../utils/Utils';
@@ -75,6 +75,9 @@ export class Bootstrap {
   public async start(): Promise<void> {
     if (isMainThread && this.started === false) {
       try {
+        // Enable unconditionally for now
+        this.logUnhandledRejection();
+        this.logUncaughtException();
         this.initialize();
         await this.storage?.open();
         await this.workerImplementation.start();
@@ -244,6 +247,18 @@ export class Bootstrap {
     this.initializeWorkerImplementation();
   }
 
+  private logUncaughtException(): void {
+    process.on('uncaughtException', (error: Error) => {
+      console.error(chalk.red('Uncaught exception: '), error);
+    });
+  }
+
+  private logUnhandledRejection(): void {
+    process.on('unhandledRejection', (reason: unknown) => {
+      console.error(chalk.red('Unhandled rejection: '), reason);
+    });
+  }
+
   private async startChargingStation(
     index: number,
     stationTemplateUrl: StationTemplateUrl