Enhance error handling in config stages handler

This commit is contained in:
Michael Friedrich 2018-04-05 17:17:30 +02:00
parent 1dd8409691
commit 75c5e6f6b0
1 changed files with 9 additions and 9 deletions

View File

@ -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({