From 06f97c87ede7b550069222d8ed74612fc848f38e Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 10 May 2016 13:42:05 +0200 Subject: [PATCH] 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 a680feaef..2aca205c4 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);