fix: fix off-by-one in ATG statuses handling
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPRequestService.ts
index e98ebdfa6ab4384eb0b7ee2683cf7cdf3302919b..1d698bd894fcaa6dd2d6194f77f0e036b8a19856 100644 (file)
@@ -27,7 +27,6 @@ import {
   cloneObject,
   formatDurationMilliSeconds,
   handleSendMessageError,
-  isNullOrUndefined,
   logger
 } from '../../utils/index.js'
 type Ajv = _Ajv.default
@@ -436,7 +435,7 @@ export abstract class OCPPRequestService {
           chargingStation.wsConnection?.send(messageToSend, (error?: Error) => {
             PerformanceStatistics.endMeasure(commandName, beginId)
             clearTimeout(sendTimeout)
-            if (isNullOrUndefined(error)) {
+            if (error == null) {
               logger.debug(
                 `${chargingStation.logPrefix()} >> Command '${commandName}' sent ${OCPPServiceUtils.getMessageTypeString(
                   messageType
@@ -455,7 +454,7 @@ export abstract class OCPPRequestService {
                 // Resolve response
                 resolve(messagePayload)
               }
-            } else if (error != null) {
+            } else {
               handleSendError(
                 new OCPPError(
                   ErrorType.GENERIC_ERROR,
@@ -484,7 +483,7 @@ export abstract class OCPPRequestService {
     }
     throw new OCPPError(
       ErrorType.SECURITY_ERROR,
-      `Cannot send command ${commandName} PDU when the charging station is in ${chargingStation?.bootNotificationResponse?.status} state on the central server`,
+      `Cannot send command ${commandName} PDU when the charging station is in ${chargingStation.bootNotificationResponse?.status} state on the central server`,
       commandName
     )
   }