From: Jérôme Benoit Date: Sun, 4 Feb 2024 10:33:28 +0000 (+0100) Subject: refactor: improve error OCPP error message X-Git-Tag: v1.2.35~23 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c510c98944b2a1f0d2c6e82f7db2eea9f8baf9a5;p=e-mobility-charging-stations-simulator.git refactor: improve error OCPP error message Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index aa68abdf..f193d148 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1865,7 +1865,10 @@ export class ChargingStation extends EventEmitter { this.emit(ChargingStationEvents.updated) } - private getCachedRequest (messageType: MessageType, messageId: string): CachedRequest | undefined { + private getCachedRequest ( + messageType: MessageType | undefined, + messageId: string + ): CachedRequest | undefined { const cachedRequest = this.requests.get(messageId) if (Array.isArray(cachedRequest)) { return cachedRequest @@ -2028,8 +2031,8 @@ export class ChargingStation extends EventEmitter { commandName ?? requestCommandName ?? Constants.UNKNOWN_COMMAND // eslint-disable-next-line @typescript-eslint/no-base-to-string }' message '${data.toString()}'${ - messageType !== MessageType.CALL_MESSAGE - ? ` matching cached request '${JSON.stringify(this.requests.get(messageId))}'` + this.requests.has(messageId) + ? ` matching cached request '${JSON.stringify(this.getCachedRequest(messageType, messageId))}'` : '' } processing error:`, error diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 0a3935c4..35b15d94 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -67,7 +67,7 @@ import { roundTo } from '../../utils/index.js' -export const getMessageTypeString = (messageType: MessageType): string => { +export const getMessageTypeString = (messageType: MessageType | undefined): string => { switch (messageType) { case MessageType.CALL_MESSAGE: return 'request'