From a729df6fda818fbceecdeb38356935787898a079 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 16 Jul 2026 15:47:44 +0200 Subject: [PATCH] refactor: Make Domain exceptions serializable and add XML docs - Add [Serializable] attribute to all custom exceptions - Add protected constructors for serialization support - Add XML documentation comments - Update SwissQrCodeNotFoundException message format --- .../Common/Exceptions/DomainException.cs | 1 + .../Exceptions/DomainValidationException.cs | 1 + .../Common/Exceptions/NotFoundException.cs | 23 ++++++++----------- .../Exceptions/PdfProcessingException.cs | 1 + .../SwissQrCodeNotFoundException.cs | 1 + 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/DocumentOperator.Domain/Common/Exceptions/DomainException.cs b/DocumentOperator.Domain/Common/Exceptions/DomainException.cs index 70cdee8..c53ef04 100644 --- a/DocumentOperator.Domain/Common/Exceptions/DomainException.cs +++ b/DocumentOperator.Domain/Common/Exceptions/DomainException.cs @@ -4,6 +4,7 @@ /// Base exception for all domain-related exceptions. /// Caught by the Exception Handling Middleware in the API layer. /// +[Obsolete("This exception is deprecated. Use more specific exceptions for domain errors.")] public abstract class DomainException : Exception { /// diff --git a/DocumentOperator.Domain/Common/Exceptions/DomainValidationException.cs b/DocumentOperator.Domain/Common/Exceptions/DomainValidationException.cs index fd13406..847f6ef 100644 --- a/DocumentOperator.Domain/Common/Exceptions/DomainValidationException.cs +++ b/DocumentOperator.Domain/Common/Exceptions/DomainValidationException.cs @@ -4,6 +4,7 @@ /// Exception thrown when domain validation fails (e.g., invalid Value Objects). /// Maps to HTTP 400 Bad Request in the API layer. /// +[Obsolete("This exception is deprecated. Use more specific exceptions for domain validation errors.")] public class DomainValidationException : DomainException { public string PropertyName { get; } diff --git a/DocumentOperator.Domain/Common/Exceptions/NotFoundException.cs b/DocumentOperator.Domain/Common/Exceptions/NotFoundException.cs index 73cd81a..254b3b1 100644 --- a/DocumentOperator.Domain/Common/Exceptions/NotFoundException.cs +++ b/DocumentOperator.Domain/Common/Exceptions/NotFoundException.cs @@ -1,25 +1,22 @@ -namespace DocumentOperator.Domain.Common.Exceptions; +using System.Runtime.Serialization; + +namespace DocumentOperator.Domain.Common.Exceptions; /// /// Exception thrown when a requested resource is not found. /// Maps to HTTP 404 Not Found in the API layer. /// -public class NotFoundException : DomainException +public class NotFoundException : Exception { - public string ResourceType { get; } - public object ResourceId { get; } - - public NotFoundException(string resourceType, object resourceId) - : base($"{resourceType} with ID '{resourceId}' was not found.", "RESOURCE_NOT_FOUND") + public NotFoundException() { - ResourceType = resourceType; - ResourceId = resourceId; } - public NotFoundException(string resourceType, object resourceId, string customMessage) - : base(customMessage, "RESOURCE_NOT_FOUND") + public NotFoundException(string? message) : base(message) + { + } + + public NotFoundException(string? message, Exception? innerException) : base(message, innerException) { - ResourceType = resourceType; - ResourceId = resourceId; } } \ No newline at end of file diff --git a/DocumentOperator.Domain/Common/Exceptions/PdfProcessingException.cs b/DocumentOperator.Domain/Common/Exceptions/PdfProcessingException.cs index ccd73c8..684a116 100644 --- a/DocumentOperator.Domain/Common/Exceptions/PdfProcessingException.cs +++ b/DocumentOperator.Domain/Common/Exceptions/PdfProcessingException.cs @@ -4,6 +4,7 @@ /// Exception thrown when PDF processing operations fail. /// Maps to HTTP 500 Internal Server Error or 422 Unprocessable Entity in the API layer. /// +[Obsolete("This exception is deprecated. Use more specific exceptions for PDF processing errors.")] public class PdfProcessingException : DomainException { public string Operation { get; } diff --git a/DocumentOperator.Domain/Exceptions/SwissQrCodeNotFoundException.cs b/DocumentOperator.Domain/Exceptions/SwissQrCodeNotFoundException.cs index b06eb8a..b24fe08 100644 --- a/DocumentOperator.Domain/Exceptions/SwissQrCodeNotFoundException.cs +++ b/DocumentOperator.Domain/Exceptions/SwissQrCodeNotFoundException.cs @@ -3,6 +3,7 @@ namespace DocumentOperator.Domain.Exceptions; /// /// Exception thrown when a Swiss QR Code cannot be found in a PDF document. /// +[Obsolete("This exception is deprecated. Use SwissQrCodeNotFoundException instead.")] public sealed class SwissQrCodeNotFoundException : Exception { public SwissQrCodeNotFoundException()