From: Jérôme Benoit Date: Fri, 30 Sep 2022 20:10:35 +0000 (+0200) Subject: Code cleanups in the OCPP incoming requests handling code X-Git-Tag: v1.1.74~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2a232a189dcf97615429a52e0deb767126cc3873;p=e-mobility-charging-stations-simulator.git Code cleanups in the OCPP incoming requests handling code Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index d70223e3..457e3468 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1489,7 +1489,7 @@ export default class ChargingStation { } logger.debug( `${this.logPrefix()} << Command '${ - requestCommandName ?? 'unknown' + requestCommandName ?? Constants.UNKNOWN_COMMAND }' received response payload: ${JSON.stringify(request)}` ); responseCallback(commandPayload, requestPayload); @@ -1519,7 +1519,7 @@ export default class ChargingStation { } logger.debug( `${this.logPrefix()} << Command '${ - requestCommandName ?? 'unknown' + requestCommandName ?? Constants.UNKNOWN_COMMAND }' received error payload: ${JSON.stringify(request)}` ); errorCallback(new OCPPError(errorType, errorMessage, requestCommandName, errorDetails)); @@ -1541,7 +1541,7 @@ export default class ChargingStation { // Log logger.error( `${this.logPrefix()} Incoming OCPP command '${ - commandName ?? requestCommandName ?? null + commandName ?? requestCommandName ?? Constants.UNKNOWN_COMMAND }' message '${data.toString()}'${ messageType !== MessageType.CALL_MESSAGE ? ` matching cached request '${JSON.stringify(this.requests.get(messageId))}'` @@ -1552,7 +1552,7 @@ export default class ChargingStation { if (error instanceof OCPPError === false) { logger.warn( `${this.logPrefix()} Error thrown at incoming OCPP command '${ - commandName ?? requestCommandName ?? null + commandName ?? requestCommandName ?? Constants.UNKNOWN_COMMAND }' message '${data.toString()}' handling is not an OCPPError:`, error ); diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index b2867425..6f5c8b8b 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -120,6 +120,8 @@ export default class Constants { static readonly DEFAULT_UI_WEBSOCKET_SERVER_HOST = 'localhost'; static readonly DEFAULT_UI_WEBSOCKET_SERVER_PORT = 8080; + static readonly UNKNOWN_COMMAND = 'unknown command'; + private constructor() { // This is intentional }