]> granicus.if.org Git - icinga2/commitdiff
Enhance error handling in config packages handler
authorMichael Friedrich <michael.friedrich@icinga.com>
Thu, 5 Apr 2018 15:21:14 +0000 (17:21 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Thu, 5 Apr 2018 15:21:14 +0000 (17:21 +0200)
lib/remote/configpackageshandler.cpp

index e3e54237b91d6603f132056939685c08b4c83fe2..7ff7567aefc016398741643a6a0ad6d70150e047 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.",
-                       HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
+                       DiagnosticInformation(ex, false));
                return;
        }
 
@@ -89,7 +89,7 @@ void ConfigPackagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& re
        String packageName = HttpUtility::GetLastParameter(params, "package");
 
        if (!ConfigPackageUtility::ValidateName(packageName)) {
-               HttpUtility::SendJsonError(response, params, 400, "Invalid package name.");
+               HttpUtility::SendJsonError(response, params, 400, "Invalid package name '" + packageName + "'.");
                return;
        }
 
@@ -97,8 +97,8 @@ void ConfigPackagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& re
                boost::mutex::scoped_lock lock(ConfigPackageUtility::GetStaticMutex());
                ConfigPackageUtility::CreatePackage(packageName);
        } catch (const std::exception& ex) {
-               HttpUtility::SendJsonError(response, params, 500, "Could not create package.",
-                       HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
+               HttpUtility::SendJsonError(response, params, 500, "Could not create package '" + packageName + "'.",
+                       DiagnosticInformation(ex, false));
                return;
        }
 
@@ -125,7 +125,7 @@ void ConfigPackagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest&
        String packageName = HttpUtility::GetLastParameter(params, "package");
 
        if (!ConfigPackageUtility::ValidateName(packageName)) {
-               HttpUtility::SendJsonError(response, params, 400, "Invalid package name.");
+               HttpUtility::SendJsonError(response, params, 400, "Invalid package name '" + packageName + "'.");
                return;
        }