From 915c88d593292e7a47c92868e4b2d3752cce4dcd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 25 Jul 2024 11:41:44 +0200 Subject: [PATCH] refactor: refine station information validation error message MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Helpers.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/charging-station/Helpers.ts b/src/charging-station/Helpers.ts index 656e77be..225c838f 100644 --- a/src/charging-station/Helpers.ts +++ b/src/charging-station/Helpers.ts @@ -179,35 +179,37 @@ export const validateStationInfo = (chargingStation: ChargingStation): void => { if (isEmpty(chargingStation.stationInfo)) { throw new BaseError('Missing charging station information') } + if (isEmpty(chargingStation.stationInfo?.chargingStationId?.trim())) { + throw new BaseError('Missing chargingStationId in stationInfo properties') + } + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const chargingStationId: string = chargingStation.stationInfo!.chargingStationId! if (isEmpty(chargingStation.stationInfo?.hashId.trim())) { - throw new BaseError('Missing hashId in stationInfo properties') + throw new BaseError(`${chargingStationId}: Missing hashId in stationInfo properties`) } if (isEmpty(chargingStation.stationInfo?.templateIndex)) { - throw new BaseError('Missing templateIndex in stationInfo properties') + throw new BaseError(`${chargingStationId}: Missing templateIndex in stationInfo properties`) } if (isEmpty(chargingStation.stationInfo?.templateName.trim())) { - throw new BaseError('Missing templateName in stationInfo properties') - } - if (isEmpty(chargingStation.stationInfo?.chargingStationId?.trim())) { - throw new BaseError('Missing chargingStationId in stationInfo properties') + throw new BaseError(`${chargingStationId}: Missing templateName in stationInfo properties`) } if (isEmpty(chargingStation.stationInfo?.maximumPower)) { - throw new BaseError('Missing maximumPower in stationInfo properties') + throw new BaseError(`${chargingStationId}: Missing maximumPower in stationInfo properties`) } if (chargingStation.stationInfo?.maximumPower != null && chargingStation.stationInfo.maximumPower <= 0) { - throw new RangeError('Invalid maximumPower value in stationInfo properties') + throw new RangeError(`${chargingStationId}: Invalid maximumPower value in stationInfo properties`) } if (isEmpty(chargingStation.stationInfo?.maximumAmperage)) { - throw new BaseError('Missing maximumAmperage in stationInfo properties') + throw new BaseError(`${chargingStationId}: Missing maximumAmperage in stationInfo properties`) } if (chargingStation.stationInfo?.maximumAmperage != null && chargingStation.stationInfo.maximumAmperage <= 0) { - throw new RangeError('Invalid maximumAmperage value in stationInfo properties') + throw new RangeError(`${chargingStationId}: Invalid maximumAmperage value in stationInfo properties`) } switch (chargingStation.stationInfo?.ocppVersion) { case OCPPVersion.VERSION_20: case OCPPVersion.VERSION_201: if (chargingStation.evses.size === 0) { - throw new BaseError('OCPP 2.0 or superior requires at least one EVSE defined in the charging station template/configuration') + throw new BaseError(`${chargingStationId}: OCPP 2.0 or superior requires at least one EVSE defined in the charging station template/configuration`) } } } -- 2.34.1