Guard transaction id fetching in ATG
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 21 Sep 2021 22:37:53 +0000 (00:37 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 21 Sep 2021 22:37:53 +0000 (00:37 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts

index a9930947f19b40384c2da629114c1674c2965700..58a40f61aa014f0720816ad1a70f1f7d9e58da50 100644 (file)
@@ -143,15 +143,16 @@ export default class AutomaticTransactionGenerator {
   private async stopTransaction(connectorId: number, reason: StopTransactionReason = StopTransactionReason.NONE): Promise<StopTransactionResponse> {
     const measureId = 'StopTransaction with ATG';
     const beginId = PerformanceStatistics.beginMeasure(measureId);
-    const transactionId = this.chargingStation.getConnector(connectorId).transactionId;
+    let transactionId = 0;
     let stopResponse: StopTransactionResponse;
     if (this.chargingStation.getConnector(connectorId)?.transactionStarted) {
+      transactionId = this.chargingStation.getConnector(connectorId).transactionId;
       stopResponse = await this.chargingStation.ocppRequestService.sendStopTransaction(transactionId,
         this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
         this.chargingStation.getTransactionIdTag(transactionId),
         reason);
     } else {
-      logger.warn(`${this.logPrefix(connectorId)} trying to stop a not started transaction ${transactionId}`);
+      logger.warn(`${this.logPrefix(connectorId)} trying to stop a not started transaction${transactionId ? ' ' + transactionId.toString() : ''}`);
     }
     PerformanceStatistics.endMeasure(measureId, beginId);
     return stopResponse;