Mercurial > hg > orthanc
comparison OrthancServer/OrthancRestApi/OrthancRestModalities.cpp @ 3345:f687e11aeb13
more explicit HTTP errors
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 05 Apr 2019 17:49:29 +0200 |
parents | 595bfee4391a |
children | 872bd3b6ec72 |
comparison
equal
deleted
inserted
replaced
3344:90b4a5001c24 | 3345:f687e11aeb13 |
---|---|
440 static void DicomQuery(RestApiPostCall& call) | 440 static void DicomQuery(RestApiPostCall& call) |
441 { | 441 { |
442 ServerContext& context = OrthancRestApi::GetContext(call); | 442 ServerContext& context = OrthancRestApi::GetContext(call); |
443 Json::Value request; | 443 Json::Value request; |
444 | 444 |
445 if (call.ParseJsonRequest(request) && | 445 if (!call.ParseJsonRequest(request) || |
446 request.type() == Json::objectValue && | 446 request.type() != Json::objectValue) |
447 request.isMember(KEY_LEVEL) && request[KEY_LEVEL].type() == Json::stringValue && | 447 { |
448 (!request.isMember(KEY_QUERY) || request[KEY_QUERY].type() == Json::objectValue)) | 448 throw OrthancException(ErrorCode_BadFileFormat, "Must provide a JSON object"); |
449 } | |
450 else if (!request.isMember(KEY_LEVEL) || | |
451 request[KEY_LEVEL].type() != Json::stringValue) | |
452 { | |
453 throw OrthancException(ErrorCode_BadFileFormat, | |
454 "The JSON body must contain field " + std::string(KEY_LEVEL)); | |
455 } | |
456 else if (request.isMember(KEY_QUERY) && | |
457 request[KEY_QUERY].type() != Json::objectValue) | |
458 { | |
459 throw OrthancException(ErrorCode_BadFileFormat, | |
460 "The field " + std::string(KEY_QUERY) + " must contain a JSON object"); | |
461 } | |
462 else | |
449 { | 463 { |
450 std::auto_ptr<QueryRetrieveHandler> handler(new QueryRetrieveHandler(context)); | 464 std::auto_ptr<QueryRetrieveHandler> handler(new QueryRetrieveHandler(context)); |
451 | 465 |
452 handler->SetModality(call.GetUriComponent("id", "")); | 466 handler->SetModality(call.GetUriComponent("id", "")); |
453 handler->SetLevel(StringToResourceType(request[KEY_LEVEL].asCString())); | 467 handler->SetLevel(StringToResourceType(request[KEY_LEVEL].asCString())); |
956 !request.isMember(KEY_RESOURCES) || | 970 !request.isMember(KEY_RESOURCES) || |
957 !request.isMember(KEY_LEVEL) || | 971 !request.isMember(KEY_LEVEL) || |
958 request[KEY_RESOURCES].type() != Json::arrayValue || | 972 request[KEY_RESOURCES].type() != Json::arrayValue || |
959 request[KEY_LEVEL].type() != Json::stringValue) | 973 request[KEY_LEVEL].type() != Json::stringValue) |
960 { | 974 { |
961 throw OrthancException(ErrorCode_BadFileFormat); | 975 throw OrthancException(ErrorCode_BadFileFormat, "Must provide a JSON body containing fields " + |
976 std::string(KEY_RESOURCES) + " and " + std::string(KEY_LEVEL)); | |
962 } | 977 } |
963 | 978 |
964 ResourceType level = StringToResourceType(request[KEY_LEVEL].asCString()); | 979 ResourceType level = StringToResourceType(request[KEY_LEVEL].asCString()); |
965 | 980 |
966 std::string localAet = Toolbox::GetJsonStringField | 981 std::string localAet = Toolbox::GetJsonStringField |
1233 } | 1248 } |
1234 | 1249 |
1235 Json::Value result; | 1250 Json::Value result; |
1236 answers.ToJson(result, true); | 1251 answers.ToJson(result, true); |
1237 call.GetOutput().AnswerJson(result); | 1252 call.GetOutput().AnswerJson(result); |
1253 } | |
1254 else | |
1255 { | |
1256 throw OrthancException(ErrorCode_BadFileFormat, "Must provide a JSON object"); | |
1238 } | 1257 } |
1239 } | 1258 } |
1240 | 1259 |
1241 | 1260 |
1242 void OrthancRestApi::RegisterModalities() | 1261 void OrthancRestApi::RegisterModalities() |