Throw errors instead of returning them
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { BaseWateringData, GeoCoordinates, PWS } from "../../types";
|
||||
import { WeatherProvider } from "../weatherProviders/WeatherProvider";
|
||||
import { ErrorCode } from "../../errors";
|
||||
|
||||
|
||||
export interface AdjustmentMethod {
|
||||
@@ -44,8 +43,6 @@ export interface AdjustmentMethodResponse {
|
||||
* watering.
|
||||
*/
|
||||
rainDelay?: number;
|
||||
/** 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;
|
||||
}
|
||||
|
||||
@@ -2,7 +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";
|
||||
import { CodedError, ErrorCode } from "../../errors";
|
||||
|
||||
|
||||
/**
|
||||
@@ -39,12 +39,7 @@ async function calculateZimmermanWateringScale(
|
||||
// Check to make sure valid data exists for all factors
|
||||
if ( !validateValues( [ "temp", "humidity", "precip" ], wateringData ) ) {
|
||||
// Default to a scale of 100% if fields are missing.
|
||||
return {
|
||||
scale: 100,
|
||||
rawData: rawData,
|
||||
errCode: ErrorCode.MissingWeatherField,
|
||||
wateringData: wateringData
|
||||
};
|
||||
throw new CodedError( ErrorCode.MissingWeatherField );
|
||||
}
|
||||
|
||||
let humidityBase = 30, tempBase = 70, precipBase = 0;
|
||||
|
||||
Reference in New Issue
Block a user