mirror of https://github.com/Icinga/icinga2.git
Enhance error handling in config stages handler
This commit is contained in:
parent
1dd8409691
commit
75c5e6f6b0
|
@ -59,10 +59,10 @@ void ConfigStagesHandler::HandleGet(const ApiUser::Ptr& user, HttpRequest& reque
|
|||
String stageName = HttpUtility::GetLastParameter(params, "stage");
|
||||
|
||||
if (!ConfigPackageUtility::ValidateName(packageName))
|
||||
return HttpUtility::SendJsonError(response, params, 400, "Invalid package name.");
|
||||
return HttpUtility::SendJsonError(response, params, 400, "Invalid package name '" + packageName + "'.");
|
||||
|
||||
if (!ConfigPackageUtility::ValidateName(stageName))
|
||||
return HttpUtility::SendJsonError(response, params, 400, "Invalid stage name.");
|
||||
return HttpUtility::SendJsonError(response, params, 400, "Invalid stage name '" + stageName + "'.");
|
||||
|
||||
ArrayData results;
|
||||
|
||||
|
@ -95,7 +95,7 @@ void ConfigStagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& requ
|
|||
String packageName = HttpUtility::GetLastParameter(params, "package");
|
||||
|
||||
if (!ConfigPackageUtility::ValidateName(packageName))
|
||||
return HttpUtility::SendJsonError(response, params, 400, "Invalid package name.");
|
||||
return HttpUtility::SendJsonError(response, params, 400, "Invalid package name '" + packageName + "'.");
|
||||
|
||||
bool reload = true;
|
||||
if (params->Contains("reload"))
|
||||
|
@ -116,8 +116,8 @@ void ConfigStagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& requ
|
|||
ConfigPackageUtility::AsyncTryActivateStage(packageName, stageName, reload);
|
||||
} catch (const std::exception& ex) {
|
||||
return HttpUtility::SendJsonError(response, params, 500,
|
||||
"Stage creation failed.",
|
||||
HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
|
||||
"Stage creation failed for '" + stageName + "'.",
|
||||
DiagnosticInformation(ex, false));
|
||||
}
|
||||
|
||||
|
||||
|
@ -153,17 +153,17 @@ void ConfigStagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest& re
|
|||
String stageName = HttpUtility::GetLastParameter(params, "stage");
|
||||
|
||||
if (!ConfigPackageUtility::ValidateName(packageName))
|
||||
return HttpUtility::SendJsonError(response, params, 400, "Invalid package name.");
|
||||
return HttpUtility::SendJsonError(response, params, 400, "Invalid package name '" + packageName + "'.");
|
||||
|
||||
if (!ConfigPackageUtility::ValidateName(stageName))
|
||||
return HttpUtility::SendJsonError(response, params, 400, "Invalid stage name.");
|
||||
return HttpUtility::SendJsonError(response, params, 400, "Invalid stage name '" + stageName + "'.");
|
||||
|
||||
try {
|
||||
ConfigPackageUtility::DeleteStage(packageName, stageName);
|
||||
} catch (const std::exception& ex) {
|
||||
return HttpUtility::SendJsonError(response, params, 500,
|
||||
"Failed to delete stage.",
|
||||
HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
|
||||
"Failed to delete stage '" + stageName + "' in package '" + packageName + "'.",
|
||||
DiagnosticInformation(ex, false));
|
||||
}
|
||||
|
||||
Dictionary::Ptr result1 = new Dictionary({
|
||||
|
|
Loading…
Reference in New Issue