# HG changeset patch # User Sebastien Jodogne # Date 1440171433 -7200 # Node ID 3be6eb3757c8b10f0cfd0d2a552b41e649cd210a # Parent 4b23310eb7e8ccbc59ff0d9a6bbf420910764446 error handling diff -r 4b23310eb7e8 -r 3be6eb3757c8 OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Fri Aug 21 17:29:16 2015 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Fri Aug 21 17:37:13 2015 +0200 @@ -549,54 +549,76 @@ std::string someInstance; - for (Json::ArrayIndex i = 0; i < content.size(); i++) + bool ok = true; + + try { - std::auto_ptr dicom(base.Clone()); - const Json::Value* payload = NULL; - - if (content[i].type() == Json::stringValue) + for (Json::ArrayIndex i = 0; ok && i < content.size(); i++) { - payload = &content[i]; - } - else if (content[i].type() == Json::objectValue) - { - if (!content[i].isMember("Content")) + std::auto_ptr dicom(base.Clone()); + const Json::Value* payload = NULL; + + if (content[i].type() == Json::stringValue) + { + payload = &content[i]; + } + else if (content[i].type() == Json::objectValue) { - LOG(ERROR) << "No payload is present for one instance in the series"; - return; + if (!content[i].isMember("Content")) + { + LOG(ERROR) << "No payload is present for one instance in the series"; + ok = false; + break; + } + + payload = &content[i]["Content"]; + + if (content[i].isMember("Tags") && + !InjectTags(*dicom, content[i]["Tags"])) + { + ok = false; + break; + } } - payload = &content[i]["Content"]; + if (payload == NULL || + payload->type() != Json::stringValue) + { + LOG(ERROR) << "The payload of the DICOM instance must be specified according to Data URI scheme"; + ok = false; + break; + } - if (content[i].isMember("Tags") && - !InjectTags(*dicom, content[i]["Tags"])) + dicom->EmbedContent(payload->asString()); + dicom->Replace(DICOM_TAG_INSTANCE_NUMBER, boost::lexical_cast(i + 1)); + dicom->Replace(DICOM_TAG_IMAGE_INDEX, boost::lexical_cast(i + 1)); + + if (!StoreCreatedInstance(someInstance, context, *dicom)) { - return; + LOG(ERROR) << "Error while creating the series"; + ok = false; + break; } } - - if (payload == NULL || - payload->type() != Json::stringValue) - { - LOG(ERROR) << "The payload of the DICOM instance must be specified according to Data URI scheme"; - return; - } - - dicom->EmbedContent(payload->asString()); - dicom->Replace(DICOM_TAG_INSTANCE_NUMBER, boost::lexical_cast(i + 1)); - dicom->Replace(DICOM_TAG_IMAGE_INDEX, boost::lexical_cast(i + 1)); - - if (!StoreCreatedInstance(someInstance, context, *dicom)) - { - LOG(ERROR) << "Error while creating the series"; - return; - } + } + catch (OrthancException&) + { + ok = false; } std::string series; if (context.GetIndex().LookupParent(series, someInstance)) { - OrthancRestApi::GetApi(call).AnswerStoredResource(call, series, ResourceType_Series, StoreStatus_Success); + if (ok) + { + OrthancRestApi::GetApi(call).AnswerStoredResource(call, series, ResourceType_Series, StoreStatus_Success); + } + else + { + // Error: Remove the newly-created series + Json::Value dummy; + context.GetIndex().DeleteResource(dummy, series, ResourceType_Series); + } } } diff -r 4b23310eb7e8 -r 3be6eb3757c8 OrthancServer/ParsedDicomFile.cpp --- a/OrthancServer/ParsedDicomFile.cpp Fri Aug 21 17:29:16 2015 +0200 +++ b/OrthancServer/ParsedDicomFile.cpp Fri Aug 21 17:37:13 2015 +0200 @@ -1398,7 +1398,7 @@ Replace(FromDcmtkBridge::Convert(DCM_Modality), "OT"); Replace(FromDcmtkBridge::Convert(DCM_ConversionType), "WSD"); Replace(FromDcmtkBridge::Convert(DCM_MIMETypeOfEncapsulatedDocument), "application/pdf"); - Replace(FromDcmtkBridge::Convert(DCM_SeriesNumber), "1"); + //Replace(FromDcmtkBridge::Convert(DCM_SeriesNumber), "1"); std::auto_ptr element(new DcmPolymorphOBOW(DCM_EncapsulatedDocument));