More refactoring of config packages errors

This commit is contained in:
Michael Friedrich 2018-04-06 09:53:54 +02:00
parent de2d18d85d
commit 36cdf8a0d2
1 changed files with 14 additions and 17 deletions

View 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.",
DiagnosticInformation(ex, false));
DiagnosticInformation(ex));
return;
}
@ -98,12 +98,13 @@ void ConfigPackagesHandler::HandlePost(const ApiUser::Ptr& user, HttpRequest& re
ConfigPackageUtility::CreatePackage(packageName);
} catch (const std::exception& ex) {
HttpUtility::SendJsonError(response, params, 500, "Could not create package '" + packageName + "'.",
DiagnosticInformation(ex, false));
DiagnosticInformation(ex));
return;
}
Dictionary::Ptr result1 = new Dictionary({
{ "code", 200 },
{ "package", packageName },
{ "status", "Created package." }
});
@ -129,27 +130,23 @@ void ConfigPackagesHandler::HandleDelete(const ApiUser::Ptr& user, HttpRequest&
return;
}
int code = 200;
String status = "Deleted package.";
DictionaryData result1;
try {
ConfigPackageUtility::DeletePackage(packageName);
} catch (const std::exception& ex) {
code = 500;
status = "Failed to delete package.";
if (HttpUtility::GetLastParameter(params, "verboseErrors"))
result1.emplace_back("diagnostic information", DiagnosticInformation(ex));
HttpUtility::SendJsonError(response, params, 500, "Failed to delete package '" + packageName + "'.",
DiagnosticInformation(ex));
}
result1.emplace_back("package", packageName);
result1.emplace_back("code", code);
result1.emplace_back("status", status);
Dictionary::Ptr result = new Dictionary({
{ "results", new Array({ new Dictionary(std::move(result1)) }) }
Dictionary::Ptr result1 = new Dictionary({
{ "code", 200 },
{ "package", packageName },
{ "status", "Created package." }
});
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);
}