Move OCPP log message formatting helper into static helpers class
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 15 Jan 2023 16:33:53 +0000 (17:33 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 15 Jan 2023 16:33:53 +0000 (17:33 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/OCPPRequestService.ts
src/charging-station/ocpp/OCPPServiceUtils.ts

index e531aa0f04bc5962518998a1affa76ded4b477c5..84930a5f628be1f99ed0e010778b55474961729c 100644 (file)
@@ -1568,7 +1568,7 @@ export default class ChargingStation {
             logger.debug(
               `${this.logPrefix()} << Command '${
                 requestCommandName ?? Constants.UNKNOWN_COMMAND
-              }' received error payload: ${JSON.stringify(request)}`
+              }' received error response payload: ${JSON.stringify(request)}`
             );
             errorCallback(new OCPPError(errorType, errorMessage, requestCommandName, errorDetails));
             break;
index c885a68e52a6f535886e103686f021f6b87bce89..023d5f95174bc07df34f3f5dbc49e214f1191d1a 100644 (file)
@@ -250,13 +250,13 @@ export default abstract class OCPPRequestService {
             try {
               chargingStation.wsConnection.send(messageToSend);
               logger.debug(
-                `${chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString(
+                `${chargingStation.logPrefix()} >> Command '${commandName}' sent ${OCPPServiceUtils.getMessageTypeString(
                   messageType
                 )} payload: ${messageToSend}`
               );
             } catch (error) {
               logger.error(
-                `${chargingStation.logPrefix()} >> Command '${commandName}' failed to send ${this.getMessageTypeString(
+                `${chargingStation.logPrefix()} >> Command '${commandName}' failed to send ${OCPPServiceUtils.getMessageTypeString(
                   messageType
                 )} payload: ${messageToSend}:`,
                 error
@@ -344,7 +344,7 @@ export default abstract class OCPPRequestService {
               );
             }
             logger.error(
-              `${chargingStation.logPrefix()} Error occurred at ${self.getMessageTypeString(
+              `${chargingStation.logPrefix()} Error occurred at ${OCPPServiceUtils.getMessageTypeString(
                 messageType
               )} command ${commandName} with PDU %j:`,
               messagePayload,
@@ -427,17 +427,6 @@ 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 handleSendMessageError(
     chargingStation: ChargingStation,
     commandName: RequestCommand | IncomingRequestCommand,
index 08618941d3308dfe7602d92df1726c599efb6552..cf2aa07eb9d9c280295a74f10e84bdb5bf273b9a 100644 (file)
@@ -9,6 +9,7 @@ import { ChargePointErrorCode } from '../../types/ocpp/ChargePointErrorCode';
 import { StandardParametersKey } from '../../types/ocpp/Configuration';
 import type { ConnectorStatusEnum } from '../../types/ocpp/ConnectorStatusEnum';
 import { ErrorType } from '../../types/ocpp/ErrorType';
+import { MessageType } from '../../types/ocpp/MessageType';
 import { MeterValueMeasurand, type MeterValuePhase } from '../../types/ocpp/MeterValues';
 import { OCPPVersion } from '../../types/ocpp/OCPPVersion';
 import {
@@ -44,6 +45,17 @@ export class OCPPServiceUtils {
     return ErrorType.FORMAT_VIOLATION;
   }
 
+  public static 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';
+    }
+  }
+
   public static isRequestCommandSupported(
     chargingStation: ChargingStation,
     command: RequestCommand