Convert exceptions for missing MediaSource or MediaAttachment to ResourceNotFoundException with appropriate message.

This commit is contained in:
Andrew Mahone 2019-11-04 14:34:21 -05:00
parent 154fb1fe9b
commit 04a96788f9

View File

@ -65,10 +65,26 @@ namespace MediaBrowser.MediaEncoding.Attachments
}
var mediaSources = await _mediaSourceManager.GetPlayackMediaSources(item, null, true, false, cancellationToken).ConfigureAwait(false);
var mediaSource = mediaSources
MediaSourceInfo mediaSource;
MediaAttachment mediaAttachment;
try
{
mediaSource = mediaSources
.First(i => string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase));
var mediaAttachment = mediaSource.MediaAttachments
}
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);