hardcoded search error messages changed to string resources

This commit is contained in:
2024-03-03 16:23:45 +01:00
Unverified
parent 2da59382a3
commit c3724921f3
7 changed files with 202 additions and 21 deletions

View File

@@ -110,8 +110,22 @@ namespace VDownload.Sources.Twitch
protected async Task<TwitchChannel> GetChannel(string id, int count)
{
byte[] token = await GetToken();
GetUsersResponse info = await _apiService.HelixGetUser(id, token);
Api.Helix.GetUsers.Response.Data userResponse = info.Data[0];
Api.Helix.GetUsers.Response.Data userResponse;
try
{
GetUsersResponse info = await _apiService.HelixGetUser(id, token);
if (info.Data.Count <= 0)
{
throw CreateExceptionChannelNotFound();
}
userResponse = info.Data[0];
}
catch (InvalidOperationException ex)
{
// TODO: Add logging
throw;
}
TwitchChannel channel = new TwitchChannel
{
@@ -130,6 +144,12 @@ namespace VDownload.Sources.Twitch
{
videos = count > 100 ? 100 : count;
GetVideosResponse videosResponse = await _apiService.HelixGetUserVideos(channel.Id, token, videos, cursor);
if (!tasks.Any() && !videosResponse.Data.Any())
{
throw CreateExceptionEmptyPlaylist();
}
videosList = videosResponse.Data;
cursor = videosResponse.Pagination.Cursor;
tasks.AddRange(videosList.Select(ParseVod));
@@ -271,19 +291,20 @@ namespace VDownload.Sources.Twitch
protected async Task<byte[]> GetToken()
{
byte[]? token = await _twitchAuthenticationService.GetToken();
if (token is null)
{
throw new MediaSearchException("Not authenticated to Twitch"); // TODO : Change to string resource
}
byte[]? token = await _twitchAuthenticationService.GetToken() ?? throw CreateExceptionNotAuthenticated();
TwitchValidationResult validation = await _twitchAuthenticationService.ValidateToken(token);
if (!validation.Success)
{
throw new MediaSearchException("Twitch authentication error"); // TODO : Change to string resource
throw CreateExceptionTokenValidationUnsuccessful();
}
return token;
}
protected MediaSearchException CreateExceptionNotAuthenticated() => new MediaSearchException("TwitchNotAuthenticated");
protected MediaSearchException CreateExceptionTokenValidationUnsuccessful() => new MediaSearchException("TwitchTokenValidationUnsuccessful");
protected MediaSearchException CreateExceptionChannelNotFound() => new MediaSearchException("TwitchChannelNotFound");
#endregion
}
}