From 36cdf8a0d2ffa03e2c770f2b94b9932f6d41bed1 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 6 Apr 2018 09:53:54 +0200 Subject: [PATCH] More refactoring of config packages errors --- lib/remote/configpackageshandler.cpp | 31 +++++++++++++--------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/remote/configpackageshandler.cpp b/lib/remote/configpackageshandler.cpp index 7ff7567ae..2ecf78d4c 100644 --- a/lib/remote/configpackageshandler.cpp +++ b/lib/remote/configpackageshandler.cpp @@ -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); }