Improve WeatherProvider error handling

This commit is contained in:
Matthew Oslan
2019-05-25 15:00:42 -04:00
parent 4c0a1d2e47
commit 4490df0aef

View File

@@ -182,6 +182,11 @@ function checkWeatherRestriction( adjustmentValue: number, weather: WateringData
export const getWeatherData = async function( req: express.Request, res: express.Response ) { export const getWeatherData = async function( req: express.Request, res: express.Response ) {
const location: string = getParameter(req.query.loc); const location: string = getParameter(req.query.loc);
if ( !weatherProvider.getWeatherData ) {
res.send( "Error: selected WeatherProvider does not support getWeatherData" );
return;
}
let coordinates: GeoCoordinates; let coordinates: GeoCoordinates;
try { try {
coordinates = await resolveCoordinates( location ); coordinates = await resolveCoordinates( location );
@@ -250,6 +255,11 @@ export const getWateringData = async function( req: express.Request, res: expres
let timeData: TimeData = getTimeData( coordinates ); let timeData: TimeData = getTimeData( coordinates );
let wateringData: WateringData; let wateringData: WateringData;
if ( adjustmentMethod !== ADJUSTMENT_METHOD.MANUAL ) { if ( adjustmentMethod !== ADJUSTMENT_METHOD.MANUAL ) {
if ( !weatherProvider.getWateringData ) {
res.send( "Error: selected WeatherProvider does not support getWateringData" );
return;
}
wateringData = await weatherProvider.getWateringData( coordinates ); wateringData = await weatherProvider.getWateringData( coordinates );
} }