[icinga-checkins] icinga.org: icinga2/master: API: Fix error message handling for invalid attributes in PUT requests

git at icinga.org git at icinga.org
Tue May 17 11:44:10 CEST 2016


Module: icinga2
Branch: master
Commit: 06f97c87ede7b550069222d8ed74612fc848f38e
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=06f97c87ede7b550069222d8ed74612fc848f38e

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Tue May 10 13:42:05 2016 +0200

API: Fix error message handling for invalid attributes in PUT requests

refs #11396

---

 lib/remote/createobjecthandler.cpp |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/remote/createobjecthandler.cpp b/lib/remote/createobjecthandler.cpp
index a680fea..2aca205 100644
--- a/lib/remote/createobjecthandler.cpp
+++ b/lib/remote/createobjecthandler.cpp
@@ -62,14 +62,29 @@ bool CreateObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
 	if (params->Contains("ignore_on_error"))
 		ignoreOnError = HttpUtility::GetLastParameter(params, "ignore_on_error");
 
-	String config = ConfigObjectUtility::CreateObjectConfig(type, name, ignoreOnError, templates, attrs);
-
 	Array::Ptr results = new Array();
 	results->Add(result1);
 
 	Dictionary::Ptr result = new Dictionary();
 	result->Set("results", results);
 
+	String config;
+
+	try {
+		config = ConfigObjectUtility::CreateObjectConfig(type, name, ignoreOnError, templates, attrs);
+	} catch (const std::exception& ex) {
+		errors->Add(DiagnosticInformation(ex));
+
+		result1->Set("errors", errors);
+		result1->Set("code", 500);
+		result1->Set("status", "Object could not be created.");
+
+		response.SetStatus(500, "Object could not be created");
+		HttpUtility::SendJsonBody(response, result);
+
+		return true;
+	}
+
 	if (!ConfigObjectUtility::CreateObject(type, name, config, errors)) {
 		result1->Set("errors", errors);
 		result1->Set("code", 500);



More information about the icinga-checkins mailing list