# HG changeset patch # User Sebastien Jodogne # Date 1763139291 -3600 # Node ID 700e04a724656445fd813e2c3cf80b5c3be9d30c # Parent 98964246e23ec647144f35e344ff97a4f7ac1897 refactoring by introducing class ErrorPayload diff -r 98964246e23e -r 700e04a72465 OrthancFramework/Sources/Enumerations.h --- a/OrthancFramework/Sources/Enumerations.h Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancFramework/Sources/Enumerations.h Fri Nov 14 17:54:51 2025 +0100 @@ -802,6 +802,12 @@ RetrieveMethod_SystemDefault = 65535 }; + enum ErrorPayloadType + { + ErrorPayloadType_None = 1, + ErrorPayloadType_Dimse = 2 + }; + ORTHANC_PUBLIC const char* EnumerationToString(ErrorCode code); diff -r 98964246e23e -r 700e04a72465 OrthancFramework/Sources/JobsEngine/IJob.h --- a/OrthancFramework/Sources/JobsEngine/IJob.h Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancFramework/Sources/JobsEngine/IJob.h Fri Nov 14 17:54:51 2025 +0100 @@ -24,6 +24,7 @@ #pragma once +#include "../OrthancException.h" #include "JobStepResult.h" #include @@ -82,6 +83,6 @@ virtual void SetUserData(const Json::Value& userData) = 0; - virtual bool LookupErrorPayload(Json::Value& payload) const = 0; + virtual void LookupErrorPayload(ErrorPayload& payload) const = 0; }; } diff -r 98964246e23e -r 700e04a72465 OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp --- a/OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp Fri Nov 14 17:54:51 2025 +0100 @@ -897,10 +897,12 @@ const std::string& details = it->second->GetLastStatus().GetDetails(); // Prefer the error payload from the job level if there is one since it should contain more information than the step error payload. - Json::Value jobErrorPayload; - if (it->second->GetJob().LookupErrorPayload(jobErrorPayload)) + ErrorPayload jobErrorPayload; + it->second->GetJob().LookupErrorPayload(jobErrorPayload); + + if (jobErrorPayload.HasContent()) { - throw OrthancException(code, details, jobErrorPayload); + throw OrthancException(code, details, jobErrorPayload.GetContent()); } else if (it->second->GetLastStatus().HasErrorPayload()) { diff -r 98964246e23e -r 700e04a72465 OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h --- a/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h Fri Nov 14 17:54:51 2025 +0100 @@ -151,9 +151,8 @@ return false; } - virtual bool LookupErrorPayload(Json::Value& payload) const ORTHANC_OVERRIDE + virtual void LookupErrorPayload(ErrorPayload& payload) const ORTHANC_OVERRIDE { - return false; } }; } diff -r 98964246e23e -r 700e04a72465 OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.h --- a/OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.h Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.h Fri Nov 14 17:54:51 2025 +0100 @@ -133,10 +133,8 @@ return false; } - virtual bool LookupErrorPayload(Json::Value& payload) const ORTHANC_OVERRIDE + virtual void LookupErrorPayload(ErrorPayload& payload) const ORTHANC_OVERRIDE { - return false; } - }; } diff -r 98964246e23e -r 700e04a72465 OrthancFramework/Sources/OrthancException.cpp --- a/OrthancFramework/Sources/OrthancException.cpp Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancFramework/Sources/OrthancException.cpp Fri Nov 14 17:54:51 2025 +0100 @@ -30,6 +30,58 @@ namespace Orthanc { + ErrorPayload::ErrorPayload(const ErrorPayload& other) : + type_(other.type_) + { + if (other.content_.get() != NULL) + { + content_.reset(new Json::Value(*other.content_)); + } + } + + + void ErrorPayload::SetContent(ErrorPayloadType type, + const Json::Value& content) + { + if (type == ErrorPayloadType_None || + content.isNull()) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + else + { + type_ = type; + content_.reset(new Json::Value(content)); + } + } + + + ErrorPayloadType ErrorPayload::GetType() const + { + if (HasContent()) + { + return type_; + } + else + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + } + + + const Json::Value& ErrorPayload::GetContent() const + { + if (HasContent()) + { + return *content_; + } + else + { + throw OrthancException(ErrorCode_BadSequenceOfCalls); + } + } + + OrthancException::OrthancException(const OrthancException& other) : errorCode_(other.errorCode_), httpStatus_(other.httpStatus_), diff -r 98964246e23e -r 700e04a72465 OrthancFramework/Sources/OrthancException.h --- a/OrthancFramework/Sources/OrthancException.h Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancFramework/Sources/OrthancException.h Fri Nov 14 17:54:51 2025 +0100 @@ -27,6 +27,7 @@ #include "Compatibility.h" // For std::unique_ptr<> #include "Enumerations.h" #include "OrthancFramework.h" + #include #include // For uint16_t @@ -45,6 +46,36 @@ }; + class ORTHANC_PUBLIC ErrorPayload + { + private: + ErrorPayload& operator= (const ErrorPayload&); // Forbidden + + ErrorPayloadType type_; + std::unique_ptr content_; + + public: + ErrorPayload() : + type_(ErrorPayloadType_None) + { + } + + explicit ErrorPayload(const ErrorPayload& other); + + void SetContent(ErrorPayloadType type, + const Json::Value& content); + + bool HasContent() const + { + return content_.get() != NULL; + } + + ErrorPayloadType GetType() const; + + const Json::Value& GetContent() const; + }; + + class ORTHANC_PUBLIC OrthancException { private: diff -r 98964246e23e -r 700e04a72465 OrthancFramework/UnitTestsSources/JobsTests.cpp --- a/OrthancFramework/UnitTestsSources/JobsTests.cpp Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancFramework/UnitTestsSources/JobsTests.cpp Fri Nov 14 17:54:51 2025 +0100 @@ -148,9 +148,8 @@ return false; } - virtual bool LookupErrorPayload(Json::Value& payload) const ORTHANC_OVERRIDE + virtual void LookupErrorPayload(ErrorPayload& payload) const ORTHANC_OVERRIDE { - return false; } }; diff -r 98964246e23e -r 700e04a72465 OrthancServer/Plugins/Engine/PluginsJob.h --- a/OrthancServer/Plugins/Engine/PluginsJob.h Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancServer/Plugins/Engine/PluginsJob.h Fri Nov 14 17:54:51 2025 +0100 @@ -95,11 +95,9 @@ return false; } - virtual bool LookupErrorPayload(Json::Value& payload) const ORTHANC_OVERRIDE + virtual void LookupErrorPayload(ErrorPayload& payload) const ORTHANC_OVERRIDE { - return false; } - }; } diff -r 98964246e23e -r 700e04a72465 OrthancServer/Sources/ServerJobs/ArchiveJob.h --- a/OrthancServer/Sources/ServerJobs/ArchiveJob.h Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.h Fri Nov 14 17:54:51 2025 +0100 @@ -154,9 +154,8 @@ return false; } - virtual bool LookupErrorPayload(Json::Value& payload) const ORTHANC_OVERRIDE + virtual void LookupErrorPayload(ErrorPayload& payload) const ORTHANC_OVERRIDE { - return false; } }; } diff -r 98964246e23e -r 700e04a72465 OrthancServer/Sources/ServerJobs/DicomRetrieveScuBaseJob.cpp --- a/OrthancServer/Sources/ServerJobs/DicomRetrieveScuBaseJob.cpp Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancServer/Sources/ServerJobs/DicomRetrieveScuBaseJob.cpp Fri Nov 14 17:54:51 2025 +0100 @@ -374,13 +374,11 @@ } } - bool DicomRetrieveScuBaseJob::LookupErrorPayload(Json::Value& payload) const + void DicomRetrieveScuBaseJob::LookupErrorPayload(ErrorPayload& payload) const { Json::Value publicContent; + GetPublicContent(publicContent); - GetPublicContent(publicContent); - payload = publicContent["Details"]; - - return true; + payload.SetContent(ErrorPayloadType_Dimse, publicContent["Details"]); } } diff -r 98964246e23e -r 700e04a72465 OrthancServer/Sources/ServerJobs/DicomRetrieveScuBaseJob.h --- a/OrthancServer/Sources/ServerJobs/DicomRetrieveScuBaseJob.h Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancServer/Sources/ServerJobs/DicomRetrieveScuBaseJob.h Fri Nov 14 17:54:51 2025 +0100 @@ -174,7 +174,6 @@ const std::string& originatorAet, const std::string& instanceId); - - virtual bool LookupErrorPayload(Json::Value& payload) const ORTHANC_OVERRIDE; + virtual void LookupErrorPayload(ErrorPayload& payload) const ORTHANC_OVERRIDE; }; } diff -r 98964246e23e -r 700e04a72465 OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.h --- a/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.h Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.h Fri Nov 14 17:54:51 2025 +0100 @@ -175,9 +175,8 @@ virtual bool GetUserData(Json::Value& userData) const ORTHANC_OVERRIDE; - virtual bool LookupErrorPayload(Json::Value& payload) const ORTHANC_OVERRIDE + virtual void LookupErrorPayload(ErrorPayload& payload) const ORTHANC_OVERRIDE { - return false; } }; } diff -r 98964246e23e -r 700e04a72465 OrthancServer/UnitTestsSources/ServerJobsTests.cpp --- a/OrthancServer/UnitTestsSources/ServerJobsTests.cpp Fri Nov 14 15:12:16 2025 +0100 +++ b/OrthancServer/UnitTestsSources/ServerJobsTests.cpp Fri Nov 14 17:54:51 2025 +0100 @@ -152,9 +152,8 @@ return false; } - virtual bool LookupErrorPayload(Json::Value& payload) const ORTHANC_OVERRIDE + virtual void LookupErrorPayload(ErrorPayload& payload) const ORTHANC_OVERRIDE { - return false; } }; @@ -232,9 +231,8 @@ return false; } - virtual bool LookupErrorPayload(Json::Value& payload) const ORTHANC_OVERRIDE + virtual void LookupErrorPayload(ErrorPayload& payload) const ORTHANC_OVERRIDE { - return false; } };