From: Jérôme Benoit Date: Sun, 21 Jan 2024 10:19:27 +0000 (+0100) Subject: refactor: improve error logging if ATG connector status is not found X-Git-Tag: v1.2.33~38 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e3fbf1aff8018d664908321682f051d49c972734;p=e-mobility-charging-stations-simulator.git refactor: improve error logging if ATG connector status is not found Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index f0d20739..85d7f43a 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -369,13 +369,16 @@ export class AutomaticTransactionGenerator { } private getConnectorStatus (connectorId: number): Status { - const connectorStatus = - this.chargingStation.getAutomaticTransactionGeneratorStatuses()?.[connectorId - 1] != null - ? clone( - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.chargingStation.getAutomaticTransactionGeneratorStatuses()![connectorId - 1] - ) - : undefined + const statusIndex = connectorId - 1 + let connectorStatus: Status | undefined + if (this.chargingStation.getAutomaticTransactionGeneratorStatuses()?.[statusIndex] != null) { + connectorStatus = clone( + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + this.chargingStation.getAutomaticTransactionGeneratorStatuses()![statusIndex] + ) + } else if (this.chargingStation.getAutomaticTransactionGeneratorStatuses() != null) { + logger.error(`${this.logPrefix(connectorId)} no status found for connector #${connectorId}`) + } if (connectorStatus != null) { connectorStatus.startDate = convertToDate(connectorStatus.startDate) connectorStatus.lastRunDate = convertToDate(connectorStatus.lastRunDate)