mirror of https://github.com/Icinga/icinga2.git
More refactoring of config packages errors
This commit is contained in:
parent
de2d18d85d
commit
36cdf8a0d2
|
@ -54,7 +54,7 @@ void ConfigPackagesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& req
|
||||||
packages = ConfigPackageUtility::GetPackages();
|
packages = ConfigPackageUtility::GetPackages();
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
HttpUtility::SendJsonError(response, params, 500, "Could not retrieve packages.",
|
HttpUtility::SendJsonError(response, params, 500, "Could not retrieve packages.",
|
||||||
DiagnosticInformation(ex, false));
|
DiagnosticInformation(ex));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,12 +98,13 @@ void ConfigPackagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& re
|
||||||
ConfigPackageUtility::CreatePackage(packageName);
|
ConfigPackageUtility::CreatePackage(packageName);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
HttpUtility::SendJsonError(response, params, 500, "Could not create package '" + packageName + "'.",
|
HttpUtility::SendJsonError(response, params, 500, "Could not create package '" + packageName + "'.",
|
||||||
DiagnosticInformation(ex, false));
|
DiagnosticInformation(ex));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr result1 = new Dictionary({
|
Dictionary::Ptr result1 = new Dictionary({
|
||||||
{ "code", 200 },
|
{ "code", 200 },
|
||||||
|
{ "package", packageName },
|
||||||
{ "status", "Created package." }
|
{ "status", "Created package." }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -129,27 +130,23 @@ void ConfigPackagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest&
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = 200;
|
|
||||||
String status = "Deleted package.";
|
|
||||||
DictionaryData result1;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ConfigPackageUtility::DeletePackage(packageName);
|
ConfigPackageUtility::DeletePackage(packageName);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
code = 500;
|
HttpUtility::SendJsonError(response, params, 500, "Failed to delete package '" + packageName + "'.",
|
||||||
status = "Failed to delete package.";
|
DiagnosticInformation(ex));
|
||||||
if (HttpUtility::GetLastParameter(params, "verboseErrors"))
|
|
||||||
result1.emplace_back("diagnostic information", DiagnosticInformation(ex));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result1.emplace_back("package", packageName);
|
Dictionary::Ptr result1 = new Dictionary({
|
||||||
result1.emplace_back("code", code);
|
{ "code", 200 },
|
||||||
result1.emplace_back("status", status);
|
{ "package", packageName },
|
||||||
|
{ "status", "Created package." }
|
||||||
Dictionary::Ptr result = new Dictionary({
|
|
||||||
{ "results", new Array({ new Dictionary(std::move(result1)) }) }
|
|
||||||
});
|
});
|
||||||
|
|
||||||
response.SetStatus(code, (code == 200) ? "OK" : "Internal Server Error");
|
Dictionary::Ptr result = new Dictionary({
|
||||||
|
{ "results", new Array({ result1 }) }
|
||||||
|
});
|
||||||
|
|
||||||
|
response.SetStatus(200, "OK");
|
||||||
HttpUtility::SendJsonBody(response, params, result);
|
HttpUtility::SendJsonBody(response, params, result);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue