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
This commit is contained in:
2026-07-16 15:47:44 +02:00
parent 88bde13422
commit a729df6fda
5 changed files with 14 additions and 13 deletions

View File

@@ -1,25 +1,22 @@
namespace DocumentOperator.Domain.Common.Exceptions;
using System.Runtime.Serialization;
namespace DocumentOperator.Domain.Common.Exceptions;
/// <summary>
/// Exception thrown when a requested resource is not found.
/// Maps to HTTP 404 Not Found in the API layer.
/// </summary>
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;
}
}