feat: new exceptions
This commit is contained in:
@@ -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