mirror of https://github.com/Icinga/icinga2.git
API: Fix error message handling for invalid attributes in PUT requests
refs #11396
This commit is contained in:
parent
b3ad32712e
commit
06f97c87ed
|
@ -62,14 +62,29 @@ bool CreateObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
|
|||
if (params->Contains("ignore_on_error"))
|
||||
ignoreOnError = HttpUtility::GetLastParameter(params, "ignore_on_error");
|
||||
|
||||
String config = ConfigObjectUtility::CreateObjectConfig(type, name, ignoreOnError, templates, attrs);
|
||||
|
||||
Array::Ptr results = new Array();
|
||||
results->Add(result1);
|
||||
|
||||
Dictionary::Ptr result = new Dictionary();
|
||||
result->Set("results", results);
|
||||
|
||||
String config;
|
||||
|
||||
try {
|
||||
config = ConfigObjectUtility::CreateObjectConfig(type, name, ignoreOnError, templates, attrs);
|
||||
} catch (const std::exception& ex) {
|
||||
errors->Add(DiagnosticInformation(ex));
|
||||
|
||||
result1->Set("errors", errors);
|
||||
result1->Set("code", 500);
|
||||
result1->Set("status", "Object could not be created.");
|
||||
|
||||
response.SetStatus(500, "Object could not be created");
|
||||
HttpUtility::SendJsonBody(response, result);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ConfigObjectUtility::CreateObject(type, name, config, errors)) {
|
||||
result1->Set("errors", errors);
|
||||
result1->Set("code", 500);
|
||||
|
|
Loading…
Reference in New Issue