mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralfms.git
synced 2026-01-27 10:23:12 +00:00
Adding error messages.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "RESTAPI_FMSObjects.h"
|
||||
#include "StorageService.h"
|
||||
#include "RESTAPI_protocol.h"
|
||||
#include "RESTAPI_errors.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
@@ -13,7 +14,7 @@ namespace OpenWifi {
|
||||
auto SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER,"");
|
||||
|
||||
if(SerialNumber.empty()) {
|
||||
BadRequest("SerialNumber must be specified.");
|
||||
BadRequest(RESTAPI::Errors::MissingSerialNumber);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,13 @@ namespace OpenWifi::RESTAPI::Errors {
|
||||
static const std::string ContactMustExist{"Contact must exist."};
|
||||
static const std::string LocationMustExist{"Location must exist."};
|
||||
static const std::string OnlyWSSupported{"This endpoint only supports WebSocket."};
|
||||
|
||||
static const std::string SerialNumberMismatch{"Serial Number mismatch."};
|
||||
static const std::string InvalidCommand{"Invalid command."};
|
||||
static const std::string NoRecordsDeleted{"No records deleted."};
|
||||
static const std::string DeviceNotConnected{"Device is not currently connected."};
|
||||
static const std::string CannotCreateWS{"Telemetry system could not create WS endpoint. Please try again."};
|
||||
static const std::string BothDeviceTypeRevision{"Both deviceType and revision must be set."};
|
||||
static const std::string IdOrSerialEmpty{"SerialNumber and Id must not be empty."};
|
||||
}
|
||||
|
||||
#endif //OWPROV_RESTAPI_ERRORS_H
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "DeviceCache.h"
|
||||
#include "uCentralProtocol.h"
|
||||
#include "RESTAPI_protocol.h"
|
||||
#include "RESTAPI_errors.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
void RESTAPI_firmwareAgeHandler::DoGet() {
|
||||
@@ -46,7 +47,7 @@ namespace OpenWifi {
|
||||
auto Revision = GetParameter(RESTAPI::Protocol::REVISION, "");
|
||||
|
||||
if (DeviceType.empty() || Revision.empty()) {
|
||||
BadRequest("Both deviceType and revision must be set.");
|
||||
BadRequest(RESTAPI::Errors::BothDeviceTypeRevision);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,9 +60,8 @@ namespace OpenWifi {
|
||||
FA.to_json(Answer);
|
||||
ReturnObject(Answer);
|
||||
return;
|
||||
} else {
|
||||
NotFound();
|
||||
}
|
||||
NotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "uCentralProtocol.h"
|
||||
#include "RESTAPI_protocol.h"
|
||||
#include "RESTAPI_utils.h"
|
||||
#include "RESTAPI_errors.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
void
|
||||
@@ -17,7 +18,7 @@ namespace OpenWifi {
|
||||
auto Obj = ParseStream();
|
||||
FMSObjects::Firmware F;
|
||||
if (!F.from_json(Obj)) {
|
||||
BadRequest("Ill formed JSON Document.");
|
||||
BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||
return;
|
||||
}
|
||||
F.id = Daemon()->CreateUUID();
|
||||
@@ -26,9 +27,8 @@ namespace OpenWifi {
|
||||
F.to_json(Answer);
|
||||
ReturnObject(Answer);
|
||||
return;
|
||||
} else {
|
||||
BadRequest("DFirmware could nto be added.");
|
||||
}
|
||||
BadRequest(RESTAPI::Errors::RecordNotCreated);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -36,7 +36,7 @@ namespace OpenWifi {
|
||||
auto UUID = GetBinding(uCentralProtocol::ID, "");
|
||||
|
||||
if(UUID.empty()) {
|
||||
BadRequest("Missing UUID.");
|
||||
BadRequest(RESTAPI::Errors::MissingUUID);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,30 +45,30 @@ namespace OpenWifi {
|
||||
Poco::JSON::Object Object;
|
||||
F.to_json(Object);
|
||||
ReturnObject(Object);
|
||||
} else {
|
||||
NotFound();
|
||||
return;
|
||||
}
|
||||
NotFound();
|
||||
}
|
||||
|
||||
void
|
||||
RESTAPI_firmwareHandler::DoDelete() {
|
||||
auto UUID = GetBinding(uCentralProtocol::ID, "");
|
||||
if(UUID.empty()) {
|
||||
BadRequest("Missing UUID.");
|
||||
BadRequest(RESTAPI::Errors::MissingUUID);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Storage()->DeleteFirmware(UUID)) {
|
||||
OK();
|
||||
} else {
|
||||
NotFound();
|
||||
return;
|
||||
}
|
||||
BadRequest(RESTAPI::Errors::CouldNotBeDeleted);
|
||||
}
|
||||
|
||||
void RESTAPI_firmwareHandler::DoPut() {
|
||||
auto UUID = GetBinding(uCentralProtocol::ID, "");
|
||||
if(UUID.empty()) {
|
||||
BadRequest("Missing UUID.");
|
||||
BadRequest(RESTAPI::Errors::MissingUUID);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace OpenWifi {
|
||||
auto Obj = ParseStream();
|
||||
FMSObjects::Firmware NewFirmware;
|
||||
if(!NewFirmware.from_json(Obj)) {
|
||||
BadRequest("Ill-formed JSON document.");
|
||||
BadRequest(RESTAPI::Errors::InvalidJSONDocument);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -100,8 +100,8 @@ namespace OpenWifi {
|
||||
Poco::JSON::Object Answer;
|
||||
F.to_json(Answer);
|
||||
ReturnObject(Answer);
|
||||
} else {
|
||||
BadRequest("Could not update the firmware entry. Please review your changes.");
|
||||
return;
|
||||
}
|
||||
BadRequest(RESTAPI::Errors::RecordNotUpdated);
|
||||
}
|
||||
}
|
||||
@@ -358,7 +358,7 @@ namespace OpenWifi {
|
||||
ProcessOptions();
|
||||
return false;
|
||||
} else if (std::find(Methods_.begin(), Methods_.end(), Request->getMethod()) == Methods_.end()) {
|
||||
BadRequest("Unsupported method");
|
||||
BadRequest(RESTAPI::Errors::UnsupportedHTTPMethod);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "RESTAPI_historyHandler.h"
|
||||
#include "StorageService.h"
|
||||
#include "RESTAPI_protocol.h"
|
||||
#include "RESTAPI_errors.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
void
|
||||
@@ -18,7 +19,7 @@ namespace OpenWifi {
|
||||
auto SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
|
||||
|
||||
if(SerialNumber.empty()) {
|
||||
BadRequest("Missing Serial Number.");
|
||||
BadRequest(RESTAPI::Errors::MissingSerialNumber);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,16 +34,16 @@ namespace OpenWifi {
|
||||
Poco::JSON::Object Answer;
|
||||
Answer.set(RESTAPI::Protocol::HISTORY, A);
|
||||
ReturnObject(Answer);
|
||||
} else {
|
||||
NotFound();
|
||||
return;
|
||||
}
|
||||
NotFound();
|
||||
}
|
||||
|
||||
void RESTAPI_historyHandler::DoDelete() {
|
||||
auto SerialNumber = GetBinding(RESTAPI::Protocol::SERIALNUMBER, "");
|
||||
auto Id = GetParameter(RESTAPI::Protocol::ID, "");
|
||||
if (SerialNumber.empty() || Id.empty()) {
|
||||
BadRequest("SerialNumber and Id must not be empty.");
|
||||
BadRequest(RESTAPI::Errors::IdOrSerialEmpty);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,10 +99,10 @@ namespace OpenWifi {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
BadRequest("Unknown command.");
|
||||
BadRequest(RESTAPI::Errors::InvalidCommand);
|
||||
return;
|
||||
}
|
||||
BadRequest("Missing command.");
|
||||
BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
|
||||
}
|
||||
|
||||
void RESTAPI_system_command::DoGet() {
|
||||
@@ -141,6 +141,6 @@ namespace OpenWifi {
|
||||
ReturnObject(Answer);
|
||||
return;
|
||||
}
|
||||
BadRequest("Unknown command.");
|
||||
BadRequest(RESTAPI::Errors::InvalidCommand);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user