mirror of https://github.com/Icinga/icinga2.git
Refactor actions error messages
This commit is contained in:
parent
4bf731fc16
commit
a00197e919
|
@ -62,7 +62,7 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
HttpUtility::SendJsonError(response, params, 404,
|
HttpUtility::SendJsonError(response, params, 404,
|
||||||
"No objects found.",
|
"No objects found.",
|
||||||
HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
|
DiagnosticInformation(ex));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -75,6 +75,11 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques
|
||||||
Log(LogNotice, "ApiActionHandler")
|
Log(LogNotice, "ApiActionHandler")
|
||||||
<< "Running action " << actionName;
|
<< "Running action " << actionName;
|
||||||
|
|
||||||
|
bool verbose = false;
|
||||||
|
|
||||||
|
if (params)
|
||||||
|
verbose = HttpUtility::GetLastParameter(params, "verbose");
|
||||||
|
|
||||||
for (const ConfigObject::Ptr& obj : objs) {
|
for (const ConfigObject::Ptr& obj : objs) {
|
||||||
try {
|
try {
|
||||||
results.emplace_back(action->Invoke(obj, params));
|
results.emplace_back(action->Invoke(obj, params));
|
||||||
|
@ -84,8 +89,9 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques
|
||||||
{ "status", "Action execution failed: '" + DiagnosticInformation(ex, false) + "'." }
|
{ "status", "Action execution failed: '" + DiagnosticInformation(ex, false) + "'." }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (HttpUtility::GetLastParameter(params, "verboseErrors"))
|
/* Exception for actions. Normally we would handle this inside SendJsonError(). */
|
||||||
fail->Set("diagnostic information", DiagnosticInformation(ex));
|
if (verbose)
|
||||||
|
fail->Set("diagnostic_information", DiagnosticInformation(ex));
|
||||||
|
|
||||||
results.emplace_back(std::move(fail));
|
results.emplace_back(std::move(fail));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue