Unify the JSON structures of responses to authorized and unauthorized requests

refs #4984
fixes #4988

Signed-off-by: Michael Friedrich <michael.friedrich@icinga.com>
This commit is contained in:
Alexander A. Klimov 2017-02-09 12:20:46 +01:00 committed by Michael Friedrich
parent 363a7f9dac
commit 3cc8982053
1 changed files with 6 additions and 16 deletions

View File

@ -186,15 +186,10 @@ void HttpServerConnection::ProcessMessageAsync(HttpRequest& request)
response.AddHeader("WWW-Authenticate", "Basic realm=\"Icinga 2\"");
if (request.Headers->Get("accept") == "application/json") {
Dictionary::Ptr result1 = new Dictionary();
result1->Set("info", "Unauthorized. Please check your user credentials.");
Array::Ptr results = new Array();
results->Add(result1);
Dictionary::Ptr result = new Dictionary();
result->Set("results", results);
result->Set("error", 401);
result->Set("status", "Unauthorized. Please check your user credentials.");
HttpUtility::SendJsonBody(response, result);
} else {
@ -213,15 +208,10 @@ void HttpServerConnection::ProcessMessageAsync(HttpRequest& request)
String errorInfo = DiagnosticInformation(ex);
if (request.Headers->Get("accept") == "application/json") {
Dictionary::Ptr result1 = new Dictionary();
result1->Set("info", errorInfo);
Array::Ptr results = new Array();
results->Add(result1);
Dictionary::Ptr result = new Dictionary();
result->Set("results", results);
result->Set("error", 503);
result->Set("status", errorInfo);
HttpUtility::SendJsonBody(response, result);
} else {