# HG changeset patch # User Sebastien Jodogne # Date 1554479369 -7200 # Node ID f687e11aeb1364066fc156fce1a0775fdb293df3 # Parent 90b4a5001c24e542ddf87c992685ca3e766fad13 more explicit HTTP errors diff -r 90b4a5001c24 -r f687e11aeb13 OrthancServer/OrthancRestApi/OrthancRestModalities.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Fri Apr 05 17:04:28 2019 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestModalities.cpp Fri Apr 05 17:49:29 2019 +0200 @@ -442,10 +442,24 @@ ServerContext& context = OrthancRestApi::GetContext(call); Json::Value request; - if (call.ParseJsonRequest(request) && - request.type() == Json::objectValue && - request.isMember(KEY_LEVEL) && request[KEY_LEVEL].type() == Json::stringValue && - (!request.isMember(KEY_QUERY) || request[KEY_QUERY].type() == Json::objectValue)) + if (!call.ParseJsonRequest(request) || + request.type() != Json::objectValue) + { + throw OrthancException(ErrorCode_BadFileFormat, "Must provide a JSON object"); + } + else if (!request.isMember(KEY_LEVEL) || + request[KEY_LEVEL].type() != Json::stringValue) + { + throw OrthancException(ErrorCode_BadFileFormat, + "The JSON body must contain field " + std::string(KEY_LEVEL)); + } + else if (request.isMember(KEY_QUERY) && + request[KEY_QUERY].type() != Json::objectValue) + { + throw OrthancException(ErrorCode_BadFileFormat, + "The field " + std::string(KEY_QUERY) + " must contain a JSON object"); + } + else { std::auto_ptr handler(new QueryRetrieveHandler(context)); @@ -958,7 +972,8 @@ request[KEY_RESOURCES].type() != Json::arrayValue || request[KEY_LEVEL].type() != Json::stringValue) { - throw OrthancException(ErrorCode_BadFileFormat); + throw OrthancException(ErrorCode_BadFileFormat, "Must provide a JSON body containing fields " + + std::string(KEY_RESOURCES) + " and " + std::string(KEY_LEVEL)); } ResourceType level = StringToResourceType(request[KEY_LEVEL].asCString()); @@ -1236,6 +1251,10 @@ answers.ToJson(result, true); call.GetOutput().AnswerJson(result); } + else + { + throw OrthancException(ErrorCode_BadFileFormat, "Must provide a JSON object"); + } }