Skip to content

Commit

Permalink
refactor: refine station information validation error message
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <[email protected]>
  • Loading branch information
jerome-benoit committed Jul 25, 2024
1 parent b55f94b commit 915c88d
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/charging-station/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}
}
}
Expand Down

0 comments on commit 915c88d

Please sign in to comment.