Introduce numeric error codes in power webapi
This commit is contained in:
parent
534f200eb9
commit
5bc264f4d2
@ -77,4 +77,8 @@ enum WebApiError {
|
|||||||
SecurityBase = 10000,
|
SecurityBase = 10000,
|
||||||
SecurityPasswordLength,
|
SecurityPasswordLength,
|
||||||
SecurityAuthSuccess,
|
SecurityAuthSuccess,
|
||||||
|
|
||||||
|
PowerBase = 11000,
|
||||||
|
PowerSerialZero,
|
||||||
|
PowerInvalidInverter,
|
||||||
};
|
};
|
||||||
@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "WebApi_power.h"
|
#include "WebApi_power.h"
|
||||||
#include "WebApi.h"
|
#include "WebApi.h"
|
||||||
|
#include "WebApi_errors.h"
|
||||||
#include <AsyncJson.h>
|
#include <AsyncJson.h>
|
||||||
#include <Hoymiles.h>
|
#include <Hoymiles.h>
|
||||||
|
|
||||||
@ -61,6 +62,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request)
|
|||||||
|
|
||||||
if (!request->hasParam("data", true)) {
|
if (!request->hasParam("data", true)) {
|
||||||
retMsg[F("message")] = F("No values found!");
|
retMsg[F("message")] = F("No values found!");
|
||||||
|
retMsg[F("code")] = WebApiError::GenericNoValueFound;
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
return;
|
return;
|
||||||
@ -70,6 +72,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request)
|
|||||||
|
|
||||||
if (json.length() > 1024) {
|
if (json.length() > 1024) {
|
||||||
retMsg[F("message")] = F("Data too large!");
|
retMsg[F("message")] = F("Data too large!");
|
||||||
|
retMsg[F("code")] = WebApiError::GenericDataTooLarge;
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
return;
|
return;
|
||||||
@ -80,6 +83,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request)
|
|||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
retMsg[F("message")] = F("Failed to parse data!");
|
retMsg[F("message")] = F("Failed to parse data!");
|
||||||
|
retMsg[F("code")] = WebApiError::GenericParseError;
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
return;
|
return;
|
||||||
@ -88,6 +92,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request)
|
|||||||
if (!(root.containsKey("serial")
|
if (!(root.containsKey("serial")
|
||||||
&& (root.containsKey("power") || root.containsKey("restart")))) {
|
&& (root.containsKey("power") || root.containsKey("restart")))) {
|
||||||
retMsg[F("message")] = F("Values are missing!");
|
retMsg[F("message")] = F("Values are missing!");
|
||||||
|
retMsg[F("code")] = WebApiError::GenericValueMissing;
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
return;
|
return;
|
||||||
@ -95,6 +100,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request)
|
|||||||
|
|
||||||
if (root[F("serial")].as<uint64_t>() == 0) {
|
if (root[F("serial")].as<uint64_t>() == 0) {
|
||||||
retMsg[F("message")] = F("Serial must be a number > 0!");
|
retMsg[F("message")] = F("Serial must be a number > 0!");
|
||||||
|
retMsg[F("code")] = WebApiError::PowerSerialZero;
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
return;
|
return;
|
||||||
@ -104,6 +110,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request)
|
|||||||
auto inv = Hoymiles.getInverterBySerial(serial);
|
auto inv = Hoymiles.getInverterBySerial(serial);
|
||||||
if (inv == nullptr) {
|
if (inv == nullptr) {
|
||||||
retMsg[F("message")] = F("Invalid inverter specified!");
|
retMsg[F("message")] = F("Invalid inverter specified!");
|
||||||
|
retMsg[F("code")] = WebApiError::PowerInvalidInverter;
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
return;
|
return;
|
||||||
@ -120,6 +127,7 @@ void WebApiPowerClass::onPowerPost(AsyncWebServerRequest* request)
|
|||||||
|
|
||||||
retMsg[F("type")] = F("success");
|
retMsg[F("type")] = F("success");
|
||||||
retMsg[F("message")] = F("Settings saved!");
|
retMsg[F("message")] = F("Settings saved!");
|
||||||
|
retMsg[F("code")] = WebApiError::GenericSuccess;
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user