From a00197e919040b8a3e86cbaa93409fa0648e19ee Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 6 Apr 2018 10:30:27 +0200 Subject: [PATCH] Refactor actions error messages --- lib/remote/actionshandler.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/remote/actionshandler.cpp b/lib/remote/actionshandler.cpp index a8b31fc10..a8a87f5d9 100644 --- a/lib/remote/actionshandler.cpp +++ b/lib/remote/actionshandler.cpp @@ -62,7 +62,7 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques } catch (const std::exception& ex) { HttpUtility::SendJsonError(response, params, 404, "No objects found.", - HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : ""); + DiagnosticInformation(ex)); return true; } } else { @@ -75,6 +75,11 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques Log(LogNotice, "ApiActionHandler") << "Running action " << actionName; + bool verbose = false; + + if (params) + verbose = HttpUtility::GetLastParameter(params, "verbose"); + for (const ConfigObject::Ptr& obj : objs) { try { 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) + "'." } }); - if (HttpUtility::GetLastParameter(params, "verboseErrors")) - fail->Set("diagnostic information", DiagnosticInformation(ex)); + /* Exception for actions. Normally we would handle this inside SendJsonError(). */ + if (verbose) + fail->Set("diagnostic_information", DiagnosticInformation(ex)); results.emplace_back(std::move(fail)); } -- 2.40.0