diff --git a/src/web/RestApi.h b/src/web/RestApi.h index 09bba06e..e1c45243 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -63,10 +63,11 @@ class RestApi { void ctrlRequest(JsonObject obj) { DynamicJsonDocument json(128); JsonObject dummy = json.as(); - if(obj[F("path")] == "ctrl") - setCtrl(obj, dummy, "*"); - else if(obj[F("path")] == "setup") - setSetup(obj, dummy, "*"); + + if(obj[F("path")] == "ctrl") + setCtrl(obj, dummy, "*"); + else if(obj[F("path")] == "setup") + setSetup(obj, dummy, "*"); } private: @@ -155,31 +156,35 @@ class RestApi { DynamicJsonDocument json(1000); DeserializationError err = deserializeJson(json, reinterpret_cast(mTmpBuf), mTmpSize); - JsonObject obj = json.as(); - AsyncJsonResponse* response = new AsyncJsonResponse(false, 200); JsonObject root = response->getRoot(); - root[F("success")] = (err) ? false : true; - if(!err) { - String path = request->url().substring(5); - if(path == "ctrl") - root[F("success")] = setCtrl(obj, root, request->client()->remoteIP().toString().c_str()); - else if(path == "setup") - root[F("success")] = setSetup(obj, root, request->client()->remoteIP().toString().c_str()); - else { - root[F("success")] = false; - root[F("error")] = F(PATH_NOT_FOUND) + path; - } + if (json.is()) { + JsonObject obj = json.as(); + + + root[F("success")] = (err) ? false : true; + + String path = request->url().substring(5); + if(path == "ctrl") + root[F("success")] = setCtrl(obj, root, request->client()->remoteIP().toString().c_str()); + else if(path == "setup") + root[F("success")] = setSetup(obj, root, request->client()->remoteIP().toString().c_str()); + else { + root[F("success")] = false; + root[F("error")] = F(PATH_NOT_FOUND) + path; + } + } else { + switch (err.code()) { - case DeserializationError::Ok: break; + case DeserializationError::Ok: root[F("error")] = F(INVALID_DATATYPE); break; case DeserializationError::IncompleteInput: root[F("error")] = F(INCOMPLETE_INPUT); break; case DeserializationError::InvalidInput: root[F("error")] = F(INVALID_INPUT); break; case DeserializationError::NoMemory: root[F("error")] = F(NOT_ENOUGH_MEM); break; default: root[F("error")] = F(DESER_FAILED); break; } - } + } response->setLength(); request->send(response); delete[] mTmpBuf; diff --git a/src/web/lang.h b/src/web/lang.h index fb5506ee..229b6b50 100644 --- a/src/web/lang.h +++ b/src/web/lang.h @@ -42,6 +42,12 @@ #define INVALID_INPUT "Invalid input" #endif +#ifdef LANG_DE + #define INVALID_DATATYPE "Ungültiger Datentyp" +#else /*LANG_EN*/ + #define INVALID_DATATYPE "Invalid datatype" +#endif + #ifdef LANG_DE #define NOT_ENOUGH_MEM "nicht genügend Speicher" #else /*LANG_EN*/