Merge pull request #6199 from Icinga/fix/action-http-code

Return 500 when no api action is successful
This commit is contained in:
Jean Flach 2018-04-06 11:20:43 +02:00 committed by GitHub
commit 6d81c5c34f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -91,11 +91,23 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques
}
}
int statusCode = 500;
String statusMessage = "No action executed successfully";
for (const Dictionary::Ptr& res : results) {
if (res->Contains("code") && res->Get("code") == 200) {
statusCode = 200;
statusMessage = "OK";
break;
}
}
response.SetStatus(statusCode, statusMessage);
Dictionary::Ptr result = new Dictionary({
{ "results", new Array(std::move(results)) }
});
response.SetStatus(200, "OK");
HttpUtility::SendJsonBody(response, params, result);
return true;