refactor: improve error OCPP error message
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 4 Feb 2024 10:33:28 +0000 (11:33 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 4 Feb 2024 10:33:28 +0000 (11:33 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/OCPPServiceUtils.ts

index aa68abdf346cdc251f99cc856708e173a7cc0cb4..f193d148b1927f921417fdce192d1c6486d4efa4 100644 (file)
@@ -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
index 0a3935c4130e408631e5b800b9432bc2229e42cd..35b15d9401051f19848660cdb78c4654a3eceb90 100644 (file)
@@ -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'