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);