From: Gunnar Beutner Date: Mon, 9 Nov 2015 11:30:30 +0000 (+0100) Subject: Fix: Detailed error message is missing when object creation via API fails X-Git-Tag: v2.4.0~37 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c44701068f7bb97eb90b3af85fb63b0de5c323c9;p=icinga2 Fix: Detailed error message is missing when object creation via API fails fixes #10580 --- diff --git a/lib/remote/createobjecthandler.cpp b/lib/remote/createobjecthandler.cpp index a7d6ec760..fe7f45c51 100644 --- a/lib/remote/createobjecthandler.cpp +++ b/lib/remote/createobjecthandler.cpp @@ -64,9 +64,20 @@ bool CreateObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r 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); + if (!ConfigObjectUtility::CreateObject(type, name, config, errors)) { result1->Set("errors", errors); - HttpUtility::SendJsonError(response, 500, "Object could not be created."); + 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; } @@ -81,12 +92,6 @@ bool CreateObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r else if (!obj && ignoreOnError) result1->Set("status", "Object was not created but 'ignore_on_error' was set to true"); - Array::Ptr results = new Array(); - results->Add(result1); - - Dictionary::Ptr result = new Dictionary(); - result->Set("results", results); - response.SetStatus(200, "OK"); HttpUtility::SendJsonBody(response, result);