mirror of https://github.com/Icinga/icinga2.git
Merge pull request #8532 from Icinga/bugfix/do-not-override-error-codes-that-are-not-200
HTTP: Do not override status codes that are not 200
This commit is contained in:
commit
db30704d14
|
@ -100,12 +100,31 @@ bool ActionsHandler::HandleRequest(
|
|||
}
|
||||
|
||||
int statusCode = 500;
|
||||
std::set<int> okStatusCodes, nonOkStatusCodes;
|
||||
|
||||
for (const Dictionary::Ptr& res : results) {
|
||||
if (res->Contains("code") && res->Get("code") >= 200 && res->Get("code") <= 299) {
|
||||
statusCode = 200;
|
||||
break;
|
||||
if (!res->Contains("code")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto code = res->Get("code");
|
||||
|
||||
if (code >= 200 && code <= 299) {
|
||||
okStatusCodes.insert(code);
|
||||
} else {
|
||||
nonOkStatusCodes.insert(code);
|
||||
}
|
||||
}
|
||||
|
||||
size_t okSize = okStatusCodes.size();
|
||||
size_t nonOkSize = nonOkStatusCodes.size();
|
||||
|
||||
if (okSize == 1u && nonOkSize == 0u) {
|
||||
statusCode = *okStatusCodes.begin();
|
||||
} else if (nonOkSize == 1u) {
|
||||
statusCode = *nonOkStatusCodes.begin();
|
||||
} else if (okSize >= 2u && nonOkSize == 0u) {
|
||||
statusCode = 200;
|
||||
}
|
||||
|
||||
response.result(statusCode);
|
||||
|
|
Loading…
Reference in New Issue