mirror of https://github.com/Icinga/icinga2.git
Merge pull request #6153 from Icinga/fix/api-no-packages
Improve error handling for empty packages in /v1/config/packages
This commit is contained in:
commit
9b0fccfd80
|
@ -48,7 +48,15 @@ void ConfigPackagesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& req
|
|||
{
|
||||
FilterUtility::CheckPermission(user, "config/query");
|
||||
|
||||
std::vector<String> packages = ConfigPackageUtility::GetPackages();
|
||||
std::vector<String> packages;
|
||||
|
||||
try {
|
||||
packages = ConfigPackageUtility::GetPackages();
|
||||
} catch (const std::exception& ex) {
|
||||
HttpUtility::SendJsonError(response, params, 500, "Could not retrieve packages.",
|
||||
HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayData results;
|
||||
|
||||
|
|
|
@ -57,9 +57,17 @@ void ConfigPackageUtility::DeletePackage(const String& name)
|
|||
|
||||
std::vector<String> ConfigPackageUtility::GetPackages()
|
||||
{
|
||||
String packageDir = GetPackageDir();
|
||||
|
||||
std::vector<String> packages;
|
||||
Utility::Glob(GetPackageDir() + "/*", std::bind(&ConfigPackageUtility::CollectDirNames,
|
||||
|
||||
/* Package directory does not exist, no packages have been created thus far. */
|
||||
if (!Utility::PathExists(packageDir))
|
||||
return packages;
|
||||
|
||||
Utility::Glob(packageDir + "/*", std::bind(&ConfigPackageUtility::CollectDirNames,
|
||||
_1, std::ref(packages)), GlobDirectory);
|
||||
|
||||
return packages;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue