[icinga-checkins] icinga.org: icinga2/master: Fix: API queries on non-existant objects cause exception
git at icinga.org
git at icinga.org
Thu Feb 4 22:40:12 CET 2016
Module: icinga2
Branch: master
Commit: 3227186c7d95745867723017dcab4b8f8c6cf4b5
URL: https://git.icinga.org/?p=icinga2.git;a=commit;h=3227186c7d95745867723017dcab4b8f8c6cf4b5
Author: Michael Friedrich <michael.friedrich at netways.de>
Date: Thu Feb 4 22:40:01 2016 +0100
Fix: API queries on non-existant objects cause exception
fixes #11088
---
lib/remote/actionshandler.cpp | 4 ++--
lib/remote/deleteobjecthandler.cpp | 11 ++++++++++-
lib/remote/modifyobjecthandler.cpp | 11 ++++++++++-
lib/remote/objectqueryhandler.cpp | 11 ++++++++++-
lib/remote/statushandler.cpp | 11 ++++++++++-
lib/remote/typequeryhandler.cpp | 11 ++++++++++-
6 files changed, 52 insertions(+), 7 deletions(-)
diff --git a/lib/remote/actionshandler.cpp b/lib/remote/actionshandler.cpp
index 9b8968a..1ab9523 100644
--- a/lib/remote/actionshandler.cpp
+++ b/lib/remote/actionshandler.cpp
@@ -64,8 +64,8 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques
try {
objs = FilterUtility::GetFilterTargets(qd, params, user);
} catch (const std::exception& ex) {
- HttpUtility::SendJsonError(response, 400,
- "Type/Filter was required but not provided or was invalid.",
+ HttpUtility::SendJsonError(response, 404,
+ "No objects found.",
HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
return true;
}
diff --git a/lib/remote/deleteobjecthandler.cpp b/lib/remote/deleteobjecthandler.cpp
index 0e9c39a..efdeb1f 100644
--- a/lib/remote/deleteobjecthandler.cpp
+++ b/lib/remote/deleteobjecthandler.cpp
@@ -61,7 +61,16 @@ bool DeleteObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
params->Set(attr, request.RequestUrl->GetPath()[3]);
}
- std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params, user);
+ std::vector<Value> objs;
+
+ try {
+ objs = FilterUtility::GetFilterTargets(qd, params, user);
+ } catch (const std::exception& ex) {
+ HttpUtility::SendJsonError(response, 404,
+ "No objects found.",
+ HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
+ return true;
+ }
bool cascade = HttpUtility::GetLastParameter(params, "cascade");
diff --git a/lib/remote/modifyobjecthandler.cpp b/lib/remote/modifyobjecthandler.cpp
index a91fdb3..f648a19 100644
--- a/lib/remote/modifyobjecthandler.cpp
+++ b/lib/remote/modifyobjecthandler.cpp
@@ -59,7 +59,16 @@ bool ModifyObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
params->Set(attr, request.RequestUrl->GetPath()[3]);
}
- std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params, user);
+ std::vector<Value> objs;
+
+ try {
+ objs = FilterUtility::GetFilterTargets(qd, params, user);
+ } catch (const std::exception& ex) {
+ HttpUtility::SendJsonError(response, 404,
+ "No objects found.",
+ HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
+ return true;
+ }
Dictionary::Ptr attrs = params->Get("attrs");
diff --git a/lib/remote/objectqueryhandler.cpp b/lib/remote/objectqueryhandler.cpp
index e19d7f2..ef6c937 100644
--- a/lib/remote/objectqueryhandler.cpp
+++ b/lib/remote/objectqueryhandler.cpp
@@ -142,7 +142,16 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
params->Set(attr, request.RequestUrl->GetPath()[3]);
}
- std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params, user);
+ std::vector<Value> objs;
+
+ try {
+ objs = FilterUtility::GetFilterTargets(qd, params, user);
+ } catch (const std::exception& ex) {
+ HttpUtility::SendJsonError(response, 404,
+ "No objects found.",
+ HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
+ return true;
+ }
Array::Ptr results = new Array();
results->Reserve(objs.size());
diff --git a/lib/remote/statushandler.cpp b/lib/remote/statushandler.cpp
index 08a293e..cce71fb 100644
--- a/lib/remote/statushandler.cpp
+++ b/lib/remote/statushandler.cpp
@@ -92,7 +92,16 @@ bool StatusHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request
if (request.RequestUrl->GetPath().size() >= 3)
params->Set("status", request.RequestUrl->GetPath()[2]);
- std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params, user);
+ std::vector<Value> objs;
+
+ try {
+ objs = FilterUtility::GetFilterTargets(qd, params, user);
+ } catch (const std::exception& ex) {
+ HttpUtility::SendJsonError(response, 404,
+ "No objects found.",
+ HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
+ return true;
+ }
Array::Ptr results = Array::FromVector(objs);
diff --git a/lib/remote/typequeryhandler.cpp b/lib/remote/typequeryhandler.cpp
index 1293163..ba8e522 100644
--- a/lib/remote/typequeryhandler.cpp
+++ b/lib/remote/typequeryhandler.cpp
@@ -97,7 +97,16 @@ bool TypeQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& requ
if (request.RequestUrl->GetPath().size() >= 3)
params->Set("name", request.RequestUrl->GetPath()[2]);
- std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params, user);
+ std::vector<Value> objs;
+
+ try {
+ objs = FilterUtility::GetFilterTargets(qd, params, user);
+ } catch (const std::exception& ex) {
+ HttpUtility::SendJsonError(response, 404,
+ "No objects found.",
+ HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
+ return true;
+ }
Array::Ptr results = new Array();
More information about the icinga-checkins
mailing list