mirror of https://github.com/Icinga/icinga2.git
Fix delete object handler returning incorrect status codes
Now a 200 OK only gets returned if all objects could be deleted fixes #10770
This commit is contained in:
parent
566dc96507
commit
9cdea730a3
|
@ -76,6 +76,8 @@ bool DeleteObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
|
||||||
|
|
||||||
Array::Ptr results = new Array();
|
Array::Ptr results = new Array();
|
||||||
|
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
BOOST_FOREACH(const ConfigObject::Ptr& obj, objs) {
|
BOOST_FOREACH(const ConfigObject::Ptr& obj, objs) {
|
||||||
Dictionary::Ptr result1 = new Dictionary();
|
Dictionary::Ptr result1 = new Dictionary();
|
||||||
result1->Set("type", type->GetName());
|
result1->Set("type", type->GetName());
|
||||||
|
@ -88,6 +90,7 @@ bool DeleteObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
|
||||||
result1->Set("code", 500);
|
result1->Set("code", 500);
|
||||||
result1->Set("status", "Object could not be deleted.");
|
result1->Set("status", "Object could not be deleted.");
|
||||||
result1->Set("errors", errors);
|
result1->Set("errors", errors);
|
||||||
|
success = false;
|
||||||
} else {
|
} else {
|
||||||
result1->Set("code", 200);
|
result1->Set("code", 200);
|
||||||
result1->Set("status", "Object was deleted.");
|
result1->Set("status", "Object was deleted.");
|
||||||
|
@ -97,7 +100,11 @@ bool DeleteObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
|
||||||
Dictionary::Ptr result = new Dictionary();
|
Dictionary::Ptr result = new Dictionary();
|
||||||
result->Set("results", results);
|
result->Set("results", results);
|
||||||
|
|
||||||
response.SetStatus(200, "OK");
|
if (!success)
|
||||||
|
response.SetStatus(500, "One or more objects could not be deleted");
|
||||||
|
else
|
||||||
|
response.SetStatus(200, "OK");
|
||||||
|
|
||||||
HttpUtility::SendJsonBody(response, result);
|
HttpUtility::SendJsonBody(response, result);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue