Skip to content

Commit

Permalink
Merge pull request #658 from KipK/no404
Browse files Browse the repository at this point in the history
switch from 404 to 200 response from REST API when there's no error
  • Loading branch information
jeremypoulter authored Jun 1, 2023
2 parents 4a97aa3 + 4d79538 commit 384bbc8
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/web_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,8 @@ void handleLimitGet(MongooseHttpServerRequest *request, MongooseHttpServerRespon
{
limit.get().serialize(response);
} else {
response->setCode(404);
response->print("{\"msg\":\"no limit\"}");
response->setCode(200);
response->print("{}");
}
}

Expand All @@ -664,7 +664,7 @@ void handleLimitPost(MongooseHttpServerRequest *request, MongooseHttpServerRespo
// todo: mqtt_publish_limit(); // update limit props to mqtt
} else {
// unused for now
response->setCode(500);
response->setCode(400);
response->print("{\"msg\":\"failed to parse JSON\"}");
}
}
Expand All @@ -675,13 +675,12 @@ void handleLimitDelete(MongooseHttpServerRequest *request, MongooseHttpServerRes
if (limit.clear()) {
response->setCode(200);
response->print("{\"msg\":\"done\"}");
// todo: mqtt_publish_limit(); // update limit props to mqtt
} else {
response->setCode(500);
response->print("{\"msg\":\"failed\"}");
}
} else {
response->setCode(404);
response->setCode(200);
response->print("{\"msg\":\"no limit\"}");
}
}
Expand Down Expand Up @@ -775,8 +774,8 @@ void handleEmeter(MongooseHttpServerRequest *request)
manual.getProperties(props);
props.serialize(response);
} else {
response->setCode(404);
response->print("{\"msg\":\"No manual override\"}");
response->setCode(200);
response->print("{}");
}
}

Expand All @@ -796,7 +795,7 @@ void handleOverridePost(MongooseHttpServerRequest *request, MongooseHttpServerRe
response->print("{\"msg\":\"Failed to claim manual overide\"}");
}
} else {
response->setCode(500);
response->setCode(400);
response->print("{\"msg\":\"Failed to parse JSON\"}");
}
}
Expand Down Expand Up @@ -917,12 +916,12 @@ handleRestart(MongooseHttpServerRequest *request) {
}
}
else {
response->setCode(405);
response->setCode(400);
response->print("{\"msg\":\"wrong payload\"}");
request->send(response);
}
} else {
response->setCode(405);
response->setCode(400);
response->print("{\"msg\":\"Couldn't parse json\"}");
request->send(response);
}
Expand Down

0 comments on commit 384bbc8

Please sign in to comment.