Factor out OCPP message type to string method
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 13 Apr 2022 21:30:12 +0000 (23:30 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 13 Apr 2022 21:30:12 +0000 (23:30 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ocpp/OCPPRequestService.ts

index ed3a8da7461d06bdeee98bbc6a8ba834de6f72aa..2813d39aad5c0ca89f4e6af9ffc31615182b4dfc 100644 (file)
@@ -154,20 +154,10 @@ export default abstract class OCPPRequestService {
             // FIXME: Handle sending error
             this.chargingStation.wsConnection.send(messageToSend);
             PerformanceStatistics.endMeasure(commandName, beginId);
-            let msgTypeStr: string;
-            switch (messageType) {
-              case MessageType.CALL_MESSAGE:
-                msgTypeStr = 'request';
-                break;
-              case MessageType.CALL_RESULT_MESSAGE:
-                msgTypeStr = 'response';
-                break;
-              case MessageType.CALL_ERROR_MESSAGE:
-                msgTypeStr = 'error';
-                break;
-            }
             logger.debug(
-              `${this.chargingStation.logPrefix()} >> Command '${commandName}' sent ${msgTypeStr} payload: ${messageToSend}`
+              `${this.chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString(
+                messageType
+              )} payload: ${messageToSend}`
             );
           } else if (!params.skipBufferingOnError) {
             // Buffer it
@@ -317,6 +307,17 @@ export default abstract class OCPPRequestService {
     return messageToSend;
   }
 
+  private getMessageTypeString(messageType: MessageType): string {
+    switch (messageType) {
+      case MessageType.CALL_MESSAGE:
+        return 'request';
+      case MessageType.CALL_RESULT_MESSAGE:
+        return 'response';
+      case MessageType.CALL_ERROR_MESSAGE:
+        return 'error';
+    }
+  }
+
   private handleRequestError(
     commandName: RequestCommand | IncomingRequestCommand,
     error: Error,