fix: improve malformed OCPP message handling
[e-mobility-charging-stations-simulator.git] / 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