changeset 6416:68001db8ed4a

removed overloaded constructors of OrthancException with HTTP status
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 15 Nov 2025 10:24:55 +0100
parents b0402a2b2ddf
children bbeacd71831b
files OrthancFramework/Sources/DicomNetworking/DicomControlUserConnection.cpp OrthancFramework/Sources/OrthancException.cpp OrthancFramework/Sources/OrthancException.h OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp OrthancServer/Sources/ServerContext.cpp
diffstat 5 files changed, 15 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomNetworking/DicomControlUserConnection.cpp	Sat Nov 15 10:19:06 2025 +0100
+++ b/OrthancFramework/Sources/DicomNetworking/DicomControlUserConnection.cpp	Sat Nov 15 10:24:55 2025 +0100
@@ -390,11 +390,11 @@
       if (response.DimseStatus == STATUS_FIND_Failed_UnableToProcess)
       {
         throw OrthancException(ErrorCode_NetworkProtocol,
-                               HttpStatus_422_UnprocessableEntity,
                                "C-FIND SCU to AET \"" +
                                parameters_.GetRemoteModality().GetApplicationEntityTitle() +
                                "\" has failed with DIMSE status " + DimseToHexString(response.DimseStatus) +
                                " (unable to process - invalid query ?)")
+          .SetHttpStatus(HttpStatus_422_UnprocessableEntity)
           .SetPayload(ErrorPayloadType_Dimse, MakeDimseErrorStatusPayload(response.DimseStatus));
       }
       else
@@ -520,11 +520,11 @@
       if (response.DimseStatus == STATUS_MOVE_Failed_UnableToProcess)
       {
         throw OrthancException(ErrorCode_NetworkProtocol,
-                               HttpStatus_422_UnprocessableEntity,
                                "C-MOVE SCU to AET \"" +
                                parameters_.GetRemoteModality().GetApplicationEntityTitle() +
                                "\" has failed with DIMSE status " + DimseToHexString(response.DimseStatus) +
                                " (unable to process - resource not found ?)")
+          .SetHttpStatus(HttpStatus_422_UnprocessableEntity)
           .SetPayload(ErrorPayloadType_Dimse, MakeDimseErrorStatusPayload(response.DimseStatus));
       }
       else
--- a/OrthancFramework/Sources/OrthancException.cpp	Sat Nov 15 10:19:06 2025 +0100
+++ b/OrthancFramework/Sources/OrthancException.cpp	Sat Nov 15 10:24:55 2025 +0100
@@ -147,32 +147,6 @@
   }
 
 
-  OrthancException::OrthancException(ErrorCode errorCode,
-                                     HttpStatus httpStatus) :
-    errorCode_(errorCode),
-    httpStatus_(httpStatus),
-    logged_(false)
-  {
-  }
-
-
-  OrthancException::OrthancException(ErrorCode errorCode,
-                                     HttpStatus httpStatus,
-                                     const std::string& details,
-                                     LogException log) :
-    errorCode_(errorCode),
-    httpStatus_(httpStatus),
-    logged_(log == LogException_Yes),
-    details_(new std::string(details))
-  {
-#if ORTHANC_ENABLE_LOGGING == 1
-    if (log == LogException_Yes)
-    {
-      LOG(ERROR) << EnumerationToString(errorCode_) << ": " << details;
-    }
-#endif
-  }
-
   ErrorCode OrthancException::GetErrorCode() const
   {
     return errorCode_;
--- a/OrthancFramework/Sources/OrthancException.h	Sat Nov 15 10:19:06 2025 +0100
+++ b/OrthancFramework/Sources/OrthancException.h	Sat Nov 15 10:24:55 2025 +0100
@@ -106,14 +106,6 @@
                      const std::string& details,
                      LogException log = LogException_Yes);
 
-    OrthancException(ErrorCode errorCode,
-                     HttpStatus httpStatus);
-
-    OrthancException(ErrorCode errorCode,
-                     HttpStatus httpStatus,
-                     const std::string& details,
-                     LogException log = LogException_Yes);
-
     ErrorCode GetErrorCode() const;
 
     HttpStatus GetHttpStatus() const;
@@ -129,6 +121,12 @@
       return logged_;
     }
 
+    OrthancException& SetHttpStatus(HttpStatus status)
+    {
+      httpStatus_ = status;
+      return *this;
+    }
+
     OrthancException& SetPayload(const ErrorPayload& payload)
     {
       payload_ = payload;
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Sat Nov 15 10:19:06 2025 +0100
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Sat Nov 15 10:24:55 2025 +0100
@@ -2718,12 +2718,14 @@
             if (transaction.HasReachedMaxStorageSize(maximumStorageSize_, instanceSize))
             {
               storeStatus_ = StoreStatus_StorageFull;
-              throw OrthancException(ErrorCode_FullStorage, HttpStatus_507_InsufficientStorage, "Maximum storage size reached"); // throw to cancel the transaction
+              throw OrthancException(ErrorCode_FullStorage, "Maximum storage size reached") // throw to cancel the transaction
+                .SetHttpStatus(HttpStatus_507_InsufficientStorage);
             }
             if (transaction.HasReachedMaxPatientCount(maximumPatientCount_, hashPatient_))
             {
               storeStatus_ = StoreStatus_StorageFull;
-              throw OrthancException(ErrorCode_FullStorage, HttpStatus_507_InsufficientStorage, "Maximum patient count reached");  // throw to cancel the transaction
+              throw OrthancException(ErrorCode_FullStorage, "Maximum patient count reached")  // throw to cancel the transaction
+                .SetHttpStatus(HttpStatus_507_InsufficientStorage);
             }
           }
           else
@@ -3015,7 +3017,7 @@
         int64_t resourceId;
         if (!transaction.LookupResource(resourceId, resourceType, publicId_))
         {
-          throw OrthancException(ErrorCode_InexistentItem, HttpStatus_404_NotFound);
+          throw OrthancException(ErrorCode_InexistentItem).SetHttpStatus(HttpStatus_404_NotFound);
         }
         else
         {
--- a/OrthancServer/Sources/ServerContext.cpp	Sat Nov 15 10:19:06 2025 +0100
+++ b/OrthancServer/Sources/ServerContext.cpp	Sat Nov 15 10:24:55 2025 +0100
@@ -855,11 +855,11 @@
 
           case StoreStatus_Failure:
             LOG(ERROR) << "Unknown store failure while storing instance " << resultPublicId;
-            throw OrthancException(ErrorCode_InternalError, HttpStatus_500_InternalServerError);
+            throw OrthancException(ErrorCode_InternalError).SetHttpStatus(HttpStatus_500_InternalServerError);
 
           case StoreStatus_StorageFull:
             LOG(ERROR) << "Storage full while storing instance " << resultPublicId;
-            throw OrthancException(ErrorCode_FullStorage, HttpStatus_507_InsufficientStorage);
+            throw OrthancException(ErrorCode_FullStorage).SetHttpStatus(HttpStatus_507_InsufficientStorage);
 
           default:
             // This should never happen