From d77553bce4a5b4d91b901c881e7db7165cd50d7d Mon Sep 17 00:00:00 2001 From: Matthew Oslan Date: Sat, 31 Aug 2019 18:36:25 -0400 Subject: [PATCH] Include an error code in every response --- errors.ts | 11 ++++++++--- routes/weather.ts | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/errors.ts b/errors.ts index e9cfe6d..c6e6c25 100644 --- a/errors.ts +++ b/errors.ts @@ -1,6 +1,8 @@ export enum ErrorCode { - /** An error was not properly handled and assigned a more specific error code. */ - UnexpectedError = 0, + /** No error occurred. This code should be included with all successful responses because the firmware expects some + * code to be present. + */ + NoError = 0, /** The watering scale could not be calculated due to a problem with the weather information. */ BadWeatherData = 1, @@ -46,7 +48,10 @@ export enum ErrorCode { /** The adjustment options could not be parsed. */ MalformedAdjustmentOptions = 50, /** A required adjustment option was not provided. */ - MissingAdjustmentOption = 51 + MissingAdjustmentOption = 51, + + /** An error was not properly handled and assigned a more specific error code. */ + UnexpectedError = 99 } /** An error with a numeric code that can be used to identify the type of error. */ diff --git a/routes/weather.ts b/routes/weather.ts index 1fca233..e3411d6 100644 --- a/routes/weather.ts +++ b/routes/weather.ts @@ -262,7 +262,8 @@ export const getWateringData = async function( req: express.Request, res: expres sunset: timeData.sunset, eip: ipToInt( remoteAddress ), rawData: undefined, - errMessage: undefined + errMessage: undefined, + errCode: 0 }; let cachedScale: CachedScale; @@ -293,6 +294,7 @@ export const getWateringData = async function( req: express.Request, res: expres } data.scale = adjustmentMethodResponse.scale; + data.errCode = adjustmentMethodResponse.errCode || 0; data.errMessage = adjustmentMethodResponse.errMessage; data.rd = adjustmentMethodResponse.rainDelay; data.rawData = adjustmentMethodResponse.rawData;