Enhance ShowMetadataApplier with logging for poster retrieval failures
ci / build-backend (push) Successful in 1m37s
ci / build-frontend (push) Successful in 53s
ci / tests (push) Successful in 1m46s
ci / sonar (push) Successful in 4m38s

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:
Leonid Pershin
2026-07-30 02:00:07 +03:00
parent 1758a93011
commit 3fecd81333
7 changed files with 54 additions and 15 deletions
@@ -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;
}
}