Add error codes to watering data errors
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { BaseWateringData, GeoCoordinates, PWS } from "../../types";
|
||||
import { WeatherProvider } from "../weatherProviders/WeatherProvider";
|
||||
import { ErrorCode } from "../../errors";
|
||||
|
||||
|
||||
export interface AdjustmentMethod {
|
||||
@@ -14,7 +15,7 @@ export interface AdjustmentMethod {
|
||||
* of this method does not have PWS support, this parameter may be ignored and coordinates may be used instead.
|
||||
* @return A Promise that will be resolved with the result of the calculation, or rejected with an error message if
|
||||
* the watering scale cannot be calculated.
|
||||
* @throws An error message can be thrown if an error occurs while calculating the watering scale.
|
||||
* @throws A CodedError may be thrown if an error occurs while calculating the watering scale.
|
||||
*/
|
||||
calculateWateringScale(
|
||||
adjustmentOptions: AdjustmentOptions,
|
||||
@@ -43,7 +44,6 @@ export interface AdjustmentMethodResponse {
|
||||
* watering.
|
||||
*/
|
||||
rainDelay?: number;
|
||||
// TODO consider removing this field and breaking backwards compatibility to handle all errors consistently.
|
||||
/**
|
||||
* An message to send to the OS firmware to indicate that an error occurred while calculating the watering
|
||||
* scale and the returned scale either defaulted to some reasonable value or was calculated with incomplete data.
|
||||
@@ -51,7 +51,9 @@ export interface AdjustmentMethodResponse {
|
||||
* but newer firmware versions may be able to alert the user that an error occurred and/or default to a
|
||||
* user-configured watering scale instead of using the one returned by the AdjustmentMethod.
|
||||
*/
|
||||
errorMessage?: string;
|
||||
errMessage?: string;
|
||||
/** A code describing the type of error that occurred (if one occurred). */
|
||||
errCode?: ErrorCode;
|
||||
/** The data that was used to calculate the watering scale, or undefined if no data was used. */
|
||||
wateringData: BaseWateringData;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as moment from "moment";
|
||||
import { AdjustmentMethod, AdjustmentMethodResponse, AdjustmentOptions } from "./AdjustmentMethod";
|
||||
import { BaseWateringData, GeoCoordinates, PWS } from "../../types";
|
||||
import { WeatherProvider } from "../weatherProviders/WeatherProvider";
|
||||
import { CodedError, ErrorCode } from "../../errors";
|
||||
|
||||
|
||||
/**
|
||||
@@ -17,7 +18,7 @@ async function calculateEToWateringScale(
|
||||
): Promise< AdjustmentMethodResponse > {
|
||||
|
||||
if ( pws ) {
|
||||
throw "ETo adjustment method does not support personal weather stations through WUnderground.";
|
||||
throw new CodedError( ErrorCode.PwsNotSupported, "ETo adjustment method does not support personal weather stations through WUnderground." );
|
||||
}
|
||||
|
||||
// Temporarily disabled since OWM forecast data is checking if rain is forecasted for 3 hours in the future.
|
||||
@@ -30,7 +31,7 @@ async function calculateEToWateringScale(
|
||||
}
|
||||
*/
|
||||
|
||||
// This will throw an error message if ETo data cannot be retrieved.
|
||||
// This will throw a CodedError if ETo data cannot be retrieved.
|
||||
const etoData: EToData = await weatherProvider.getEToData( coordinates );
|
||||
|
||||
let baseETo: number;
|
||||
@@ -40,7 +41,7 @@ async function calculateEToWateringScale(
|
||||
if ( adjustmentOptions && "baseETo" in adjustmentOptions ) {
|
||||
baseETo = adjustmentOptions.baseETo
|
||||
} else {
|
||||
throw "A baseline potential ETo must be provided.";
|
||||
throw new CodedError( ErrorCode.MissingAdjustmentOption, "A baseline potential ETo must be provided." );
|
||||
}
|
||||
|
||||
if ( adjustmentOptions && "elevation" in adjustmentOptions ) {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { AdjustmentMethod, AdjustmentMethodResponse, AdjustmentOptions } from ".
|
||||
import { GeoCoordinates, PWS, ZimmermanWateringData } from "../../types";
|
||||
import { validateValues } from "../weather";
|
||||
import { WeatherProvider } from "../weatherProviders/WeatherProvider";
|
||||
import { ErrorCode } from "../../errors";
|
||||
|
||||
|
||||
/**
|
||||
@@ -41,7 +42,8 @@ async function calculateZimmermanWateringScale(
|
||||
return {
|
||||
scale: 100,
|
||||
rawData: rawData,
|
||||
errorMessage: "Necessary field(s) were missing from ZimmermanWateringData.",
|
||||
errCode: ErrorCode.MissingWeatherField,
|
||||
errMessage: "Necessary field(s) were missing from ZimmermanWateringData.",
|
||||
wateringData: wateringData
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user