hardcoded search error messages changed to string resources
This commit is contained in:
@@ -8,13 +8,21 @@ namespace VDownload.Sources.Common
|
||||
{
|
||||
public class MediaSearchException : Exception
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public string StringCode { get; protected set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
public MediaSearchException() : base() { }
|
||||
|
||||
public MediaSearchException(string message) : base(message) { }
|
||||
|
||||
public MediaSearchException(string message, Exception inner) : base(message, inner) { }
|
||||
public MediaSearchException(string stringCode) : this(stringCode, stringCode) { }
|
||||
public MediaSearchException(string stringCode, string message) : base(message)
|
||||
{
|
||||
StringCode = stringCode;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace VDownload.Sources.Common
|
||||
return video;
|
||||
}
|
||||
}
|
||||
throw new MediaSearchException("Invalid url"); // TODO : Change to string resource
|
||||
throw CreateExceptionUnknownMediaType();
|
||||
}
|
||||
|
||||
public async Task<Playlist> SearchPlaylist(string url, int maxVideoCount)
|
||||
@@ -47,7 +47,7 @@ namespace VDownload.Sources.Common
|
||||
return video;
|
||||
}
|
||||
}
|
||||
throw new MediaSearchException("Invalid url"); // TODO : Change to string resource
|
||||
throw CreateExceptionUnknownMediaType();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -60,6 +60,9 @@ namespace VDownload.Sources.Common
|
||||
|
||||
protected abstract IEnumerable<SearchRegexPlaylist> GetPlaylistRegexes();
|
||||
|
||||
protected MediaSearchException CreateExceptionUnknownMediaType() => new MediaSearchException("UnknownMediaType");
|
||||
protected MediaSearchException CreateExceptionEmptyPlaylist() => new MediaSearchException("EmptyPlaylist");
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,8 @@ namespace VDownload.Sources
|
||||
return await mapping.Service.SearchVideo(url);
|
||||
}
|
||||
}
|
||||
throw new MediaSearchException("Source is not supported"); // TODO : Change to string resource
|
||||
|
||||
throw CreateExceptionSourceNotSupported();
|
||||
}
|
||||
|
||||
public async Task<Playlist> SearchPlaylist(string url, int maxVideoCount)
|
||||
@@ -72,7 +73,8 @@ namespace VDownload.Sources
|
||||
return await mapping.Service.SearchPlaylist(url, maxVideoCount);
|
||||
}
|
||||
}
|
||||
throw new MediaSearchException("Source is not supported"); // TODO : Change to string resource
|
||||
|
||||
throw CreateExceptionSourceNotSupported();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -81,14 +83,17 @@ namespace VDownload.Sources
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
private void BaseUrlCheck(string url)
|
||||
protected void BaseUrlCheck(string url)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(url))
|
||||
{
|
||||
throw new MediaSearchException("Url cannot be empty"); // TODO : Change to string resource
|
||||
throw CreateExceptionEmptyUrl();
|
||||
}
|
||||
}
|
||||
|
||||
protected MediaSearchException CreateExceptionSourceNotSupported() => new MediaSearchException("SourceNotSupported");
|
||||
protected MediaSearchException CreateExceptionEmptyUrl() => new MediaSearchException("EmptyUrl");
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user