]> granicus.if.org Git - icinga2/commitdiff
More refactoring of config packages errors
authorMichael Friedrich <michael.friedrich@icinga.com>
Fri, 6 Apr 2018 07:53:54 +0000 (09:53 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Fri, 6 Apr 2018 07:53:54 +0000 (09:53 +0200)
lib/remote/configpackageshandler.cpp

index 7ff7567aefc016398741643a6a0ad6d70150e047..2ecf78d4ccc0e7d7bc65613e2806081783555eca 100644 (file)
@@ -54,7 +54,7 @@ void ConfigPackagesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& req
                packages = ConfigPackageUtility::GetPackages();
        } catch (const std::exception& ex) {
                HttpUtility::SendJsonError(response, params, 500, "Could not retrieve packages.",
-                       DiagnosticInformation(ex, false));
+                       DiagnosticInformation(ex));
                return;
        }
 
@@ -98,12 +98,13 @@ void ConfigPackagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& re
                ConfigPackageUtility::CreatePackage(packageName);
        } catch (const std::exception& ex) {
                HttpUtility::SendJsonError(response, params, 500, "Could not create package '" + packageName + "'.",
-                       DiagnosticInformation(ex, false));
+                       DiagnosticInformation(ex));
                return;
        }
 
        Dictionary::Ptr result1 = new Dictionary({
                { "code", 200 },
+               { "package", packageName },
                { "status", "Created package." }
        });
 
@@ -129,27 +130,23 @@ void ConfigPackagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest&
                return;
        }
 
-       int code = 200;
-       String status = "Deleted package.";
-       DictionaryData result1;
-
        try {
                ConfigPackageUtility::DeletePackage(packageName);
        } catch (const std::exception& ex) {
-               code = 500;
-               status = "Failed to delete package.";
-               if (HttpUtility::GetLastParameter(params, "verboseErrors"))
-                       result1.emplace_back("diagnostic information", DiagnosticInformation(ex));
+               HttpUtility::SendJsonError(response, params, 500, "Failed to delete package '" + packageName + "'.",
+                       DiagnosticInformation(ex));
        }
 
-       result1.emplace_back("package", packageName);
-       result1.emplace_back("code", code);
-       result1.emplace_back("status", status);
+       Dictionary::Ptr result1 = new Dictionary({
+               { "code", 200 },
+               { "package", packageName },
+               { "status", "Created package." }
+       });
 
        Dictionary::Ptr result = new Dictionary({
-               { "results", new Array({ new Dictionary(std::move(result1)) }) }
+               { "results", new Array({ result1 }) }
        });
 
-       response.SetStatus(code, (code == 200) ? "OK" : "Internal Server Error");
+       response.SetStatus(200, "OK");
        HttpUtility::SendJsonBody(response, params, result);
 }