fix: ensure charging stations array global property is initialized
[e-mobility-charging-stations-simulator.git] / ui / web / src / composables / UIClient.ts
index 81a322d31c73d1d2a0222f2086fa6d498e796a22..9a6920418d3adb255f64a8e97e50be35e9586640 100644 (file)
@@ -16,7 +16,7 @@ type ResponseHandler = {
 }
 
 export class UIClient {
-  private static readonly instances: Map<number, UIClient> = new Map<number, UIClient>()
+  private static instance: UIClient | null = null
 
   private ws!: WebSocket
   private responseHandlers: Map<string, ResponseHandler>
@@ -26,16 +26,11 @@ export class UIClient {
     this.responseHandlers = new Map<string, ResponseHandler>()
   }
 
-  public static getInstance(
-    serverId: number,
-    uiServerConfiguration?: UIServerConfigurationSection
-  ): UIClient {
-    if (!UIClient.instances.has(serverId) && uiServerConfiguration != null) {
-      UIClient.instances.set(serverId, new UIClient(uiServerConfiguration))
-    } else if (!UIClient.instances.has(serverId)) {
-      throw new Error(`UI client instance not found for server id: ${serverId}`)
+  public static getInstance(uiServerConfiguration: UIServerConfigurationSection): UIClient {
+    if (UIClient.instance === null) {
+      UIClient.instance = new UIClient(uiServerConfiguration)
     }
-    return UIClient.instances.get(serverId)!
+    return UIClient.instance
   }
 
   public registerWSEventListener<K extends keyof WebSocketEventMap>(
@@ -212,8 +207,10 @@ export class UIClient {
           reject(responsePayload)
           break
         default:
-          console.error(
-            `Response status for procedure '${procedureName}' not supported: '${responsePayload.status}'`
+          reject(
+            new Error(
+              `Response status for procedure '${procedureName}' not supported: '${responsePayload.status}'`
+            )
           )
       }
       this.responseHandlers.delete(uuid)