aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs
diff options
context:
space:
mode:
authorAndrew Mahone <andrew.mahone@gmail.com>2019-11-04 14:34:21 -0500
committerAndrew Mahone <andrew.mahone@gmail.com>2019-11-04 14:34:21 -0500
commit04a96788f9f3ea20b05d3c57d16d222ba7a53101 (patch)
tree3fba593ff6b54bd6e273a20bcc4207badbe0c701 /MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs
parent154fb1fe9b45892807a9bea9abb282380bfd9383 (diff)
Convert exceptions for missing MediaSource or MediaAttachment to ResourceNotFoundException with appropriate message.
Diffstat (limited to 'MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs')
-rw-r--r--MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs24
1 files changed, 20 insertions, 4 deletions
diff --git a/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs b/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs
index 1c214d5d3..be5908cce 100644
--- a/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs
+++ b/MediaBrowser.MediaEncoding/Attachments/AttachmentExtractor.cs
@@ -65,10 +65,26 @@ namespace MediaBrowser.MediaEncoding.Attachments
}
var mediaSources = await _mediaSourceManager.GetPlayackMediaSources(item, null, true, false, cancellationToken).ConfigureAwait(false);
- var mediaSource = mediaSources
- .First(i => string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase));
- var mediaAttachment = mediaSource.MediaAttachments
- .First(i => i.Index == attachmentStreamIndex);
+ MediaSourceInfo mediaSource;
+ MediaAttachment mediaAttachment;
+ try
+ {
+ mediaSource = mediaSources
+ .First(i => string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase));
+ }
+ catch (Exception ex) when (ex is ArgumentNullException || ex is InvalidOperationException)
+ {
+ throw new ResourceNotFoundException($"MediaSource {mediaSourceId} not found");
+ }
+ try
+ {
+ mediaAttachment = mediaSource.MediaAttachments
+ .First(i => i.Index == attachmentStreamIndex);
+ }
+ catch (Exception ex) when (ex is ArgumentNullException || ex is InvalidOperationException)
+ {
+ throw new ResourceNotFoundException($"MediaSource {mediaSourceId} has no attachment with stream index {attachmentStreamIndex}");
+ }
var attachmentStream = await GetAttachmentStream(mediaSource, mediaAttachment, cancellationToken)
.ConfigureAwait(false);