Commit 4da300c5 authored by Micha Mueller's avatar Micha Mueller
Browse files

Minor improvements to RestAPI server

parent af62fd36
......@@ -183,9 +183,8 @@ void RESTHttpsServer::handle_request(http::request<Body>& req, Send&& send) {
res.body() = "Invalid endpoint\n";
}
#ifdef DEBUG
ServerLOG(info) << "Responding:\n" << res.body();
#endif
res.prepare_payload();
send(std::move(res));
return;
......
......@@ -44,7 +44,7 @@ RestAPI::RestAPI(serverSettings_t settings,
}
void RestAPI::GET_help(endpointArgs) {
res.body() = restCheatSheet + _manager->newRestCheatSheet;
res.body() = restCheatSheet + _manager->restCheatSheet;
res.result(http::status::ok);
}
......@@ -108,9 +108,7 @@ void RestAPI::GET_average(endpointArgs) {
const std::string interval = getQuery("interval", queries);
if (plugin == "" || sensor == "") {
const std::string err = "Request malformed: plugin or sensor query missing";
RESTAPILOG(error) << err;
res.body() = err;
res.body() = "Request malformed: plugin or sensor query missing\n";
res.result(http::status::bad_request);
return;
}
......@@ -118,7 +116,14 @@ void RestAPI::GET_average(endpointArgs) {
uint64_t time = 0;
if (interval != "") {
try {
time = std::stoul(interval);
} catch (const std::exception& e) {
RESTAPILOG(warning) << "Bad interval query: " << e.what();
res.body() = "Bad interval query!\n";
res.result(http::status::bad_request);
return;
}
}
res.body() = "Plugin not found!\n";
......@@ -244,7 +249,7 @@ void RestAPI::PUT_reload(endpointArgs) {
removeTopics(p);
p.configurator->clearConfig();
} else {
res.body() = "Plugin " + plugin + ": Configuration reloaded\n";
res.body() = "Plugin " + plugin + ": Configuration reloaded.\n";
res.result(http::status::ok);
for (const auto& g : p.configurator->getSensorGroups()) {
g->init(_io);
......@@ -252,7 +257,7 @@ void RestAPI::PUT_reload(endpointArgs) {
}
}
} else {
res.body() = "Plugin " + plugin + ": Could not reload configuration";
res.body() = "Plugin " + plugin + ": Could not reload configuration.\n";
res.result(http::status::internal_server_error);
}
......@@ -305,9 +310,7 @@ bool RestAPI::checkTopics(dl_t p) {
void RestAPI::PUT_analytics_reload(endpointArgs) {
if (_manager->getStatus() != AnalyticsManager::LOADED) {
const std::string err = "AnalyticsManager is not loaded!\n";
RESTAPILOG(error) << err;
res.body() = err;
res.body() = "AnalyticsManager is not loaded!\n";
res.result(http::status::internal_server_error);
return;
}
......
......@@ -13,7 +13,6 @@
#include <boost/asio.hpp>
#include "includes/PluginDefinitions.h"
#include "globalconfiguration.h"
#include "../analytics/AnalyticsManager.h"
#include "mqttchecker.h"
#include "MQTTPusher.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment