Add error codes to watering data errors
This commit is contained in:
@@ -4,6 +4,7 @@ import { GeoCoordinates, WeatherData, ZimmermanWateringData } from "../../types"
|
||||
import { httpJSONRequest } from "../weather";
|
||||
import { WeatherProvider } from "./WeatherProvider";
|
||||
import { approximateSolarRadiation, CloudCoverInfo, EToData } from "../adjustmentMethods/EToAdjustmentMethod";
|
||||
import { CodedError, ErrorCode } from "../../errors";
|
||||
|
||||
export default class DarkSkyWeatherProvider extends WeatherProvider {
|
||||
|
||||
@@ -28,11 +29,11 @@ export default class DarkSkyWeatherProvider extends WeatherProvider {
|
||||
yesterdayData = await httpJSONRequest( yesterdayUrl );
|
||||
} catch ( err ) {
|
||||
console.error( "Error retrieving weather information from Dark Sky:", err );
|
||||
throw "An error occurred while retrieving weather information from Dark Sky."
|
||||
throw new CodedError( ErrorCode.WeatherApiError, "An error occurred while retrieving weather information from Dark Sky." );
|
||||
}
|
||||
|
||||
if ( !yesterdayData.hourly || !yesterdayData.hourly.data ) {
|
||||
throw "Necessary field(s) were missing from weather information returned by Dark Sky.";
|
||||
throw new CodedError( ErrorCode.MissingWeatherField, "Necessary field(s) were missing from weather information returned by Dark Sky." );
|
||||
}
|
||||
|
||||
const samples = [
|
||||
@@ -41,7 +42,7 @@ export default class DarkSkyWeatherProvider extends WeatherProvider {
|
||||
|
||||
// Fail if not enough data is available.
|
||||
if ( samples.length !== 24 ) {
|
||||
throw "Insufficient data was returned by Dark Sky.";
|
||||
throw new CodedError( ErrorCode.InsufficientWeatherData, "Insufficient data was returned by Dark Sky." );
|
||||
}
|
||||
|
||||
const totals = { temp: 0, humidity: 0, precip: 0 };
|
||||
@@ -122,7 +123,7 @@ export default class DarkSkyWeatherProvider extends WeatherProvider {
|
||||
try {
|
||||
historicData = await httpJSONRequest( historicUrl );
|
||||
} catch (err) {
|
||||
throw "An error occurred while retrieving weather information from Dark Sky."
|
||||
throw new CodedError( ErrorCode.WeatherApiError, "An error occurred while retrieving weather information from Dark Sky." );
|
||||
}
|
||||
|
||||
const cloudCoverInfo: CloudCoverInfo[] = historicData.hourly.data.map( ( hour ): CloudCoverInfo => {
|
||||
|
||||
Reference in New Issue
Block a user