From: Jérôme Benoit Date: Thu, 25 Jul 2024 09:41:44 +0000 (+0200) Subject: refactor: refine station information validation error message X-Git-Tag: ocpp-server@v1.5.0~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=915c88d593292e7a47c92868e4b2d3752cce4dcd;p=e-mobility-charging-stations-simulator.git refactor: refine station information validation error message Signed-off-by: Jérôme Benoit --- 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`) } } }