From 2a232a189dcf97615429a52e0deb767126cc3873 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 30 Sep 2022 22:10:35 +0200 Subject: [PATCH] Code cleanups in the OCPP incoming requests handling code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ChargingStation.ts | 8 ++++---- src/utils/Constants.ts | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) 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 } -- 2.34.1