]> granicus.if.org Git - icinga2/commitdiff
Fix: Detailed error message is missing when object creation via API fails
authorGunnar Beutner <gunnar@beutner.name>
Mon, 9 Nov 2015 11:30:30 +0000 (12:30 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Mon, 9 Nov 2015 11:30:30 +0000 (12:30 +0100)
fixes #10580

lib/remote/createobjecthandler.cpp

index a7d6ec760caedc2ad5bb635ae386136ab2f048a9..fe7f45c51acbd98e7245bbbde2c81ed51642db35 100644 (file)
@@ -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);