refactor(youtube): log service failures and decouple error messages

YouTubeMusicService swallowed the exception into an ErrorOr description
with no trace on the server side. Adds ILogger to the three operations.
The download activity no longer names yt-dlp in its messages, since the
downloader is an implementation detail behind IYouTubeDownloaderService.
This commit is contained in:
2026-07-20 07:27:57 +02:00
parent 0570852cac
commit 3d20be6e95
2 changed files with 7 additions and 3 deletions
@@ -1,5 +1,6 @@
using ErrorOr;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Musify.Application.Contracts;
using Musify.Infrastructure.Configuration;
using YouTubeMusicAPI.Client;
@@ -9,7 +10,7 @@ using YouTubeMusicAPI.Pagination;
namespace Musify.Infrastructure.Services
{
public class YouTubeMusicService(YouTubeConfiguration configuration, IMemoryCache cache) : IYouTubeMusicService
public class YouTubeMusicService(YouTubeConfiguration configuration, IMemoryCache cache, ILogger<YouTubeMusicService> logger) : IYouTubeMusicService
{
private readonly YouTubeMusicClient client = new(geographicalLocation: configuration.GeographicalLocation);
@@ -34,6 +35,7 @@ namespace Musify.Infrastructure.Services
}
catch (Exception exception)
{
logger.LogError(exception, "YouTube Music search failed for query '{Query}'", query);
return Error.Failure(description: $"YouTube Music search failed: {exception.Message}");
}
@@ -87,6 +89,7 @@ namespace Musify.Infrastructure.Services
}
catch (Exception exception)
{
logger.LogError(exception, "Failed to resolve YouTube stream for '{VideoId}'", videoId);
return Error.Failure(description: $"Failed to resolve YouTube stream for '{videoId}': {exception.Message}");
}
@@ -138,6 +141,7 @@ namespace Musify.Infrastructure.Services
}
catch (Exception exception)
{
logger.LogError(exception, "Failed to load YouTube song info for '{VideoId}'", videoId);
return Error.Failure(description: $"Failed to load YouTube song info for '{videoId}': {exception.Message}");
}
}