Fix: API queries on non-existant objects cause exception

fixes #11088
This commit is contained in:
Michael Friedrich 2016-02-04 22:40:01 +01:00
parent 611ff869e1
commit 3227186c7d
6 changed files with 52 additions and 7 deletions

View File

@ -64,8 +64,8 @@ bool ActionsHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& reques
try { try {
objs = FilterUtility::GetFilterTargets(qd, params, user); objs = FilterUtility::GetFilterTargets(qd, params, user);
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
HttpUtility::SendJsonError(response, 400, HttpUtility::SendJsonError(response, 404,
"Type/Filter was required but not provided or was invalid.", "No objects found.",
HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : ""); HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
return true; return true;
} }

View File

@ -61,7 +61,16 @@ bool DeleteObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
params->Set(attr, request.RequestUrl->GetPath()[3]); params->Set(attr, request.RequestUrl->GetPath()[3]);
} }
std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params, user); std::vector<Value> objs;
try {
objs = FilterUtility::GetFilterTargets(qd, params, user);
} catch (const std::exception& ex) {
HttpUtility::SendJsonError(response, 404,
"No objects found.",
HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
return true;
}
bool cascade = HttpUtility::GetLastParameter(params, "cascade"); bool cascade = HttpUtility::GetLastParameter(params, "cascade");

View File

@ -59,7 +59,16 @@ bool ModifyObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
params->Set(attr, request.RequestUrl->GetPath()[3]); params->Set(attr, request.RequestUrl->GetPath()[3]);
} }
std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params, user); std::vector<Value> objs;
try {
objs = FilterUtility::GetFilterTargets(qd, params, user);
} catch (const std::exception& ex) {
HttpUtility::SendJsonError(response, 404,
"No objects found.",
HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
return true;
}
Dictionary::Ptr attrs = params->Get("attrs"); Dictionary::Ptr attrs = params->Get("attrs");

View File

@ -142,7 +142,16 @@ bool ObjectQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& re
params->Set(attr, request.RequestUrl->GetPath()[3]); params->Set(attr, request.RequestUrl->GetPath()[3]);
} }
std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params, user); std::vector<Value> objs;
try {
objs = FilterUtility::GetFilterTargets(qd, params, user);
} catch (const std::exception& ex) {
HttpUtility::SendJsonError(response, 404,
"No objects found.",
HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
return true;
}
Array::Ptr results = new Array(); Array::Ptr results = new Array();
results->Reserve(objs.size()); results->Reserve(objs.size());

View File

@ -92,7 +92,16 @@ bool StatusHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& request
if (request.RequestUrl->GetPath().size() >= 3) if (request.RequestUrl->GetPath().size() >= 3)
params->Set("status", request.RequestUrl->GetPath()[2]); params->Set("status", request.RequestUrl->GetPath()[2]);
std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params, user); std::vector<Value> objs;
try {
objs = FilterUtility::GetFilterTargets(qd, params, user);
} catch (const std::exception& ex) {
HttpUtility::SendJsonError(response, 404,
"No objects found.",
HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
return true;
}
Array::Ptr results = Array::FromVector(objs); Array::Ptr results = Array::FromVector(objs);

View File

@ -97,7 +97,16 @@ bool TypeQueryHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& requ
if (request.RequestUrl->GetPath().size() >= 3) if (request.RequestUrl->GetPath().size() >= 3)
params->Set("name", request.RequestUrl->GetPath()[2]); params->Set("name", request.RequestUrl->GetPath()[2]);
std::vector<Value> objs = FilterUtility::GetFilterTargets(qd, params, user); std::vector<Value> objs;
try {
objs = FilterUtility::GetFilterTargets(qd, params, user);
} catch (const std::exception& ex) {
HttpUtility::SendJsonError(response, 404,
"No objects found.",
HttpUtility::GetLastParameter(params, "verboseErrors") ? DiagnosticInformation(ex) : "");
return true;
}
Array::Ptr results = new Array(); Array::Ptr results = new Array();