Enhance ShowMetadataApplier with logging for poster retrieval failures
Updated the ShowMetadataApplier class to include logging for scenarios where show posters are not retrieved successfully. Introduced logging statements to capture warnings when poster URLs are empty or when downloads fail, improving traceability and debugging capabilities. Additionally, updated related tests to ensure proper logging behavior during poster processing.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TeleWave.Application.Common.Interfaces;
|
||||
using TeleWave.Application.Common.Models;
|
||||
using TeleWave.Application.Library.Genres;
|
||||
@@ -16,7 +17,8 @@ public sealed class ShowMetadataApplier(
|
||||
IMetadataProviderResolver resolver,
|
||||
IImageDownloader downloader,
|
||||
IImageStore imageStore,
|
||||
GenreMatcher genreMatcher
|
||||
GenreMatcher genreMatcher,
|
||||
ILogger<ShowMetadataApplier> logger
|
||||
)
|
||||
{
|
||||
/// <summary>
|
||||
@@ -84,12 +86,28 @@ public sealed class ShowMetadataApplier(
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
// Три исхода — три разные починки, и снаружи они неразличимы: шоу просто остаётся без
|
||||
// постера. Пишем в лог, какой именно случился.
|
||||
if (string.IsNullOrEmpty(posterUrl))
|
||||
{
|
||||
logger.LogWarning(
|
||||
"Постер для «{Show}» не проставлен: источник не вернул ссылку на картинку",
|
||||
show.Name
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
var downloaded = await downloader.DownloadAsync(posterUrl, cancellationToken);
|
||||
if (downloaded is null)
|
||||
{
|
||||
// Подробности (статус, исключение) пишет сам загрузчик.
|
||||
logger.LogWarning(
|
||||
"Постер для «{Show}» не проставлен: {Url} не скачался",
|
||||
show.Name,
|
||||
posterUrl
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
var image = Image.Create(ImageCategory.ShowPoster, downloaded.Extension, show.Name);
|
||||
dbContext.Images.Add(image);
|
||||
@@ -99,6 +117,11 @@ public sealed class ShowMetadataApplier(
|
||||
downloaded.Content,
|
||||
cancellationToken
|
||||
);
|
||||
logger.LogInformation(
|
||||
"Постер для «{Show}» сохранён как изображение {ImageId}",
|
||||
show.Name,
|
||||
image.Id
|
||||
);
|
||||
return image.Id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user