feat: new exceptions
This commit is contained in:
@@ -52,10 +52,10 @@ public sealed class Collection
|
||||
public static Collection Create(long ownerTelegramId, string name, string? description = null)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
throw new DomainException("Collection name cannot be empty.");
|
||||
throw new DomainValidationException("Collection name cannot be empty.");
|
||||
|
||||
if (name.Length > 100)
|
||||
throw new DomainException("Collection name must be 100 characters or less.");
|
||||
throw new DomainValidationException("Collection name must be 100 characters or less.");
|
||||
|
||||
return new Collection(Guid.NewGuid(), ownerTelegramId, name, description);
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public sealed class Collection
|
||||
EnsureRole(requestingTelegramId, CollectionRole.Owner);
|
||||
|
||||
if (role == CollectionRole.Owner)
|
||||
throw new DomainException("Cannot assign Owner role. Transfer ownership instead.");
|
||||
throw new InsufficientPermissionException("Cannot assign Owner role. Transfer ownership instead.");
|
||||
|
||||
var existing = _members.FirstOrDefault(m => m.TelegramId == telegramId);
|
||||
if (existing is not null)
|
||||
@@ -129,7 +129,7 @@ public sealed class Collection
|
||||
EnsureRole(requestingTelegramId, CollectionRole.Manager);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(newName))
|
||||
throw new DomainException("Collection name cannot be empty.");
|
||||
throw new DomainValidationException("Collection name cannot be empty.");
|
||||
|
||||
Name = newName.Trim();
|
||||
UpdatedAt = DateTimeOffset.UtcNow;
|
||||
@@ -219,7 +219,7 @@ public sealed class Collection
|
||||
{
|
||||
var role = GetRole(telegramId);
|
||||
if (role is null || role < minimumRole)
|
||||
throw new DomainException($"Action requires at least {minimumRole} role.");
|
||||
throw new InsufficientPermissionException($"Action requires at least {minimumRole} role.");
|
||||
}
|
||||
|
||||
private static string GenerateToken() =>
|
||||
|
||||
@@ -52,10 +52,10 @@ public sealed class CollectionInvite
|
||||
DateTimeOffset? expiresAt = null)
|
||||
{
|
||||
if (role == CollectionRole.Owner)
|
||||
throw new DomainException("Cannot create an invite with Owner role.");
|
||||
throw new InsufficientPermissionException("Cannot create an invite with Owner role.");
|
||||
|
||||
if (expiresAt.HasValue && expiresAt.Value <= DateTimeOffset.UtcNow)
|
||||
throw new DomainException("Invite expiry must be in the future.");
|
||||
throw new DomainValidationException("Invite expiry must be in the future.");
|
||||
|
||||
return new CollectionInvite(collectionId, createdBy, role, expiresAt);
|
||||
}
|
||||
|
||||
@@ -75,10 +75,10 @@ public sealed class MediaItem
|
||||
IEnumerable<Tag>? tags = null)
|
||||
{
|
||||
if (type == MediaType.Text && string.IsNullOrWhiteSpace(caption))
|
||||
throw new DomainException("Text media must have non-empty caption.");
|
||||
throw new DomainValidationException("Text media must have non-empty caption.");
|
||||
|
||||
if (type != MediaType.Text && source is null)
|
||||
throw new DomainException("Non-text media must have a source (Telegram fileId or S3 key).");
|
||||
throw new DomainValidationException("Non-text media must have a source (Telegram fileId or S3 key).");
|
||||
|
||||
var item = new MediaItem(
|
||||
Guid.NewGuid(),
|
||||
@@ -111,7 +111,7 @@ public sealed class MediaItem
|
||||
{
|
||||
if (_tags.Contains(tag)) return;
|
||||
if (_tags.Count >= 20)
|
||||
throw new DomainException("Cannot have more than 20 tags per item.");
|
||||
throw new DomainValidationException("Cannot have more than 20 tags per item.");
|
||||
|
||||
_tags.Add(tag);
|
||||
UpdatedAt = DateTimeOffset.UtcNow;
|
||||
@@ -128,7 +128,7 @@ public sealed class MediaItem
|
||||
{
|
||||
var distinct = newTags.Distinct().ToList();
|
||||
if (distinct.Count > 20)
|
||||
throw new DomainException("Cannot have more than 20 tags per item.");
|
||||
throw new DomainValidationException("Cannot have more than 20 tags per item.");
|
||||
|
||||
_tags.Clear();
|
||||
_tags.AddRange(distinct);
|
||||
|
||||
Reference in New Issue
Block a user