fix: improve malformed OCPP message handling
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 21 Jan 2024 10:05:24 +0000 (11:05 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 21 Jan 2024 10:05:24 +0000 (11:05 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts

index 3f0069aff5c093dcf6b248cdfd8b0cafdc250b3d..10b32dce9ca2f632dfb9b6f59573b1a1dc409982 100644 (file)
@@ -1947,11 +1947,14 @@ export class ChargingStation extends EventEmitter {
         )
       }
     } catch (error) {
+      if (!Array.isArray(request)) {
+        logger.error(`${this.logPrefix()} Incoming message '${request}' parsing error:`, error)
+        return
+      }
       let commandName: IncomingRequestCommand | undefined
       let requestCommandName: RequestCommand | IncomingRequestCommand | undefined
       let errorCallback: ErrorCallback
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      const [, messageId] = request!
+      const [, messageId] = request
       switch (messageType) {
         case MessageType.CALL_MESSAGE:
           [, , commandName] = request as IncomingRequest