Mercurial > hg > orthanc
changeset 6412:700e04a72465
refactoring by introducing class ErrorPayload
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Fri, 14 Nov 2025 17:54:51 +0100 |
| parents | 98964246e23e |
| children | 342980a5192d |
| files | OrthancFramework/Sources/Enumerations.h OrthancFramework/Sources/JobsEngine/IJob.h OrthancFramework/Sources/JobsEngine/JobsRegistry.cpp OrthancFramework/Sources/JobsEngine/Operations/SequenceOfOperationsJob.h OrthancFramework/Sources/JobsEngine/SetOfCommandsJob.h OrthancFramework/Sources/OrthancException.cpp OrthancFramework/Sources/OrthancException.h OrthancFramework/UnitTestsSources/JobsTests.cpp OrthancServer/Plugins/Engine/PluginsJob.h OrthancServer/Sources/ServerJobs/ArchiveJob.h OrthancServer/Sources/ServerJobs/DicomRetrieveScuBaseJob.cpp OrthancServer/Sources/ServerJobs/DicomRetrieveScuBaseJob.h OrthancServer/Sources/ServerJobs/ThreadedSetOfInstancesJob.h OrthancServer/UnitTestsSources/ServerJobsTests.cpp |
| diffstat | 14 files changed, 108 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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 <boost/noncopyable.hpp> @@ -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; }; }
--- 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()) {
--- 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; } }; }
--- 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; } - }; }
--- 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_),
--- 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 <json/value.h> #include <stdint.h> // For uint16_t @@ -45,6 +46,36 @@ }; + class ORTHANC_PUBLIC ErrorPayload + { + private: + ErrorPayload& operator= (const ErrorPayload&); // Forbidden + + ErrorPayloadType type_; + std::unique_ptr<Json::Value> 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:
--- 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; } };
--- 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; } - }; }
--- 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; } }; }
--- 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"]); } }
--- 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; }; }
--- 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; } }; }
--- 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; } };
