fix issue where OK was not sent on successfull API call

This commit is contained in:
proddy
2021-11-02 10:42:20 +01:00
parent 2c5c4d6e04
commit 54889fec41

View File

@@ -90,9 +90,11 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) {
} else if (command_ret == CommandRet::NOT_FOUND) {
ret_code = 400; // Bad request
} else if (command_ret == CommandRet::OK) {
ret_code = 200; //OK
if (output.isNull()) {
output["message"] = "OK"; // only add if there is no json output already
ret_code = 200; // OK
// if there was not json output from the call, default to the message 'OK'.
// this will be used for example when calling endpoints e.g. /api/thermostat/temp
if (!output.size()) {
output["message"] = "OK";
}
} else {
ret_code = 400; // Bad request
@@ -108,7 +110,7 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) {
Serial.print(COLOR_YELLOW);
Serial.print("return code: ");
Serial.println(ret_code);
if (output.size() != 0) {
if (output.size()) {
serializeJsonPretty(output, Serial);
}
Serial.println();