fix: do not send UI protocol response if no handler is found
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 27 May 2023 13:57:56 +0000 (15:57 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 27 May 2023 13:57:56 +0000 (15:57 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ui-server/AbstractUIServer.ts
src/charging-station/ui-server/UIHttpServer.ts
src/charging-station/ui-server/UIWebSocketServer.ts
src/charging-station/ui-server/ui-services/AbstractUIService.ts

index 8552a572f4bf08ab3134da682f3c444f2aa54773..c21185fe2c890d8bc2f293dcb68ba756f1a517ef 100644 (file)
@@ -52,6 +52,10 @@ export abstract class AbstractUIServer {
     return this.uiServices.get(protocolVersion)?.requestHandler(request);
   }
 
+  public hasResponseHandler(uuid: string): boolean {
+    return this.responseHandlers.has(uuid);
+  }
+
   protected startHttpServer(): void {
     if (this.httpServer.listening === false) {
       this.httpServer.listen(this.uiServerConfiguration.options);
index ccafb0845df0307a2577e34b68f5d4e8742ff18f..159559df1f4cacb6eebaa1f67b8e6cca66ac030a 100644 (file)
@@ -44,7 +44,7 @@ export class UIHttpServer extends AbstractUIServer {
   public sendResponse(response: ProtocolResponse): void {
     const [uuid, payload] = response;
     try {
-      if (this.responseHandlers.has(uuid) === true) {
+      if (this.hasResponseHandler(uuid) === true) {
         const res = this.responseHandlers.get(uuid) as ServerResponse;
         res
           .writeHead(this.responseStatusToStatusCode(payload.status), {
index 5ddf0e5901109321606ac5607b6aa821a7956648..dd5b6163576dc86b7bb22bb93c9cdb7223e31e91 100644 (file)
@@ -112,7 +112,7 @@ export class UIWebSocketServer extends AbstractUIServer {
   public sendResponse(response: ProtocolResponse): void {
     const responseId = response[0];
     try {
-      if (this.responseHandlers.has(responseId)) {
+      if (this.hasResponseHandler(responseId)) {
         const ws = this.responseHandlers.get(responseId) as WebSocket;
         if (ws?.readyState === WebSocket.OPEN) {
           ws.send(JSON.stringify(response));
index 0531011f95b6397bbbb432f932de31db7b2cf33a..1ec6cf93b20e77363f08ecbb79cb9c10ed9cf656 100644 (file)
@@ -116,7 +116,9 @@ export abstract class AbstractUIService {
   // }
 
   public sendResponse(messageId: string, responsePayload: ResponsePayload): void {
-    this.uiServer.sendResponse(this.uiServer.buildProtocolResponse(messageId, responsePayload));
+    if (this.uiServer.hasResponseHandler(messageId)) {
+      this.uiServer.sendResponse(this.uiServer.buildProtocolResponse(messageId, responsePayload));
+    }
   }
 
   public logPrefix = (modName: string, methodName: string): string => {