fix: only send UI server response when needed
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 26 May 2023 12:55:36 +0000 (14:55 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 26 May 2023 12:55:36 +0000 (14:55 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ui-server/UIHttpServer.ts
src/charging-station/ui-server/UIWebSocketServer.ts
src/charging-station/ui-server/ui-services/AbstractUIService.ts

index b99ef36a80cf9ec223db9f1a77a0b32d1e095af6..a831446b9c5f93d0e8bd3cd55543dc79957b88bc 100644 (file)
@@ -125,6 +125,11 @@ export class UIHttpServer extends AbstractUIServer {
                   body ?? Constants.EMPTY_FREEZED_OBJECT
                 )
               )
+              .then((protocolResponse: ProtocolResponse) => {
+                if (Utils.isNullOrUndefined(protocolResponse)) {
+                  this.sendResponse(protocolResponse);
+                }
+              })
               .catch(Constants.EMPTY_FUNCTION);
           });
       } else {
index cc00db13f233af42975062331f054992135ce510..5ddf0e5901109321606ac5607b6aa821a7956648 100644 (file)
@@ -49,7 +49,15 @@ export class UIWebSocketServer extends AbstractUIServer {
         }
         const [requestId] = request as ProtocolRequest;
         this.responseHandlers.set(requestId, ws);
-        this.uiServices.get(version)?.requestHandler(request).catch(Constants.EMPTY_FUNCTION);
+        this.uiServices
+          .get(version)
+          ?.requestHandler(request)
+          .then((protocolResponse: ProtocolResponse) => {
+            if (!Utils.isNullOrUndefined(protocolResponse)) {
+              this.sendResponse(protocolResponse);
+            }
+          })
+          .catch(Constants.EMPTY_FUNCTION);
       });
       ws.on('error', (error) => {
         logger.error(`${this.logPrefix(moduleName, 'start.ws.onerror')} WebSocket error:`, error);
index 392a63edf296fb9179359fbb086ecf21e35f2821..0531011f95b6397bbbb432f932de31db7b2cf33a 100644 (file)
@@ -100,22 +100,20 @@ export abstract class AbstractUIService {
         errorDetails: (error as OCPPError).details,
       };
     }
-    // Send response
     if (!Utils.isNullOrUndefined(responsePayload)) {
-      this.sendResponse(messageId, responsePayload);
       return this.uiServer.buildProtocolResponse(messageId, responsePayload);
     }
   }
 
-  public sendRequest(
-    messageId: string,
-    procedureName: ProcedureName,
-    requestPayload: RequestPayload
-  ): void {
-    this.uiServer.sendRequest(
-      this.uiServer.buildProtocolRequest(messageId, procedureName, requestPayload)
-    );
-  }
+  // public sendRequest(
+  //   messageId: string,
+  //   procedureName: ProcedureName,
+  //   requestPayload: RequestPayload
+  // ): void {
+  //   this.uiServer.sendRequest(
+  //     this.uiServer.buildProtocolRequest(messageId, procedureName, requestPayload)
+  //   );
+  // }
 
   public sendResponse(messageId: string, responsePayload: ResponsePayload): void {
     this.uiServer.sendResponse(this.uiServer.buildProtocolResponse(messageId, responsePayload));