diff --git a/include/WebApi_errors.h b/include/WebApi_errors.h index 3c06468d..0e4099a0 100644 --- a/include/WebApi_errors.h +++ b/include/WebApi_errors.h @@ -77,4 +77,8 @@ enum WebApiError { SecurityBase = 10000, SecurityPasswordLength, SecurityAuthSuccess, + + PowerBase = 11000, + PowerSerialZero, + PowerInvalidInverter, }; \ No newline at end of file diff --git a/src/WebApi_power.cpp b/src/WebApi_power.cpp index 6426f171..97e4aba6 100644 --- a/src/WebApi_power.cpp +++ b/src/WebApi_power.cpp @@ -4,6 +4,7 @@ */ #include "WebApi_power.h" #include "WebApi.h" +#include "WebApi_errors.h" #include #include @@ -61,6 +62,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request) if (!request->hasParam("data", true)) { retMsg[F("message")] = F("No values found!"); + retMsg[F("code")] = WebApiError::GenericNoValueFound; response->setLength(); request->send(response); return; @@ -70,6 +72,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request) if (json.length() > 1024) { retMsg[F("message")] = F("Data too large!"); + retMsg[F("code")] = WebApiError::GenericDataTooLarge; response->setLength(); request->send(response); return; @@ -80,6 +83,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request) if (error) { retMsg[F("message")] = F("Failed to parse data!"); + retMsg[F("code")] = WebApiError::GenericParseError; response->setLength(); request->send(response); return; @@ -88,6 +92,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request) if (!(root.containsKey("serial") && (root.containsKey("power") || root.containsKey("restart")))) { retMsg[F("message")] = F("Values are missing!"); + retMsg[F("code")] = WebApiError::GenericValueMissing; response->setLength(); request->send(response); return; @@ -95,6 +100,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request) if (root[F("serial")].as() == 0) { retMsg[F("message")] = F("Serial must be a number > 0!"); + retMsg[F("code")] = WebApiError::PowerSerialZero; response->setLength(); request->send(response); return; @@ -104,6 +110,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request) auto inv = Hoymiles.getInverterBySerial(serial); if (inv == nullptr) { retMsg[F("message")] = F("Invalid inverter specified!"); + retMsg[F("code")] = WebApiError::PowerInvalidInverter; response->setLength(); request->send(response); return; @@ -120,6 +127,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request) retMsg[F("type")] = F("success"); retMsg[F("message")] = F("Settings saved!"); + retMsg[F("code")] = WebApiError::GenericSuccess; response->setLength(); request->send(response);