Fixed: Improve Artist/Album lookup error handling

This commit is contained in:
bakerboy448 2025-08-26 18:25:38 -05:00
parent f8664bf2f1
commit 3eb9ff605f

View file

@ -88,6 +88,10 @@ public Artist GetArtistInfo(string foreignArtistId, int metadataProfileId)
{
throw new BadRequestException(foreignArtistId);
}
else if (httpResponse.StatusCode == HttpStatusCode.ServiceUnavailable)
{
throw new SkyHookException("Unable to communicate with LidarrAPI. Service temporarily unavailable (503).");
}
else
{
throw new HttpException(httpRequest, httpResponse);
@ -166,6 +170,10 @@ public Tuple<string, Album, List<ArtistMetadata>> GetAlbumInfo(string foreignAlb
{
throw new BadRequestException(foreignAlbumId);
}
else if (httpResponse.StatusCode == HttpStatusCode.ServiceUnavailable)
{
throw new SkyHookException("Unable to communicate with LidarrAPI. Service temporarily unavailable (503).");
}
else
{
throw new HttpException(httpRequest, httpResponse);
@ -298,8 +306,14 @@ public List<Album> SearchForNewAlbum(string title, string artist)
.Where(x => x != null)
.ToList();
}
catch (HttpException)
catch (HttpException ex)
{
if (ex.Response != null && ex.Response.StatusCode == HttpStatusCode.ServiceUnavailable)
{
_logger.Warn("Album search failed for '{0}', service temporarily unavailable", title);
return new List<Album>();
}
throw new SkyHookException("Search for '{0}' failed. Unable to communicate with LidarrAPI.", title);
}
catch (Exception ex)
@ -332,25 +346,51 @@ public List<object> SearchForNewEntity(string title)
if (IsMbidQuery(lowerTitle))
{
var artist = SearchForNewArtist(lowerTitle);
if (artist.Any())
List<Artist> artist = null;
try
{
artist = SearchForNewArtist(lowerTitle);
}
catch (SkyHookException ex)
{
_logger.Warn(ex, $"Artist search failed for '{lowerTitle}', will try album search.");
}
catch (Exception ex)
{
_logger.Warn(ex, $"Artist search failed for '{lowerTitle}', will try album search.");
}
if (artist != null && artist.Any())
{
return new List<object> { artist.First() };
}
var album = SearchForNewAlbum(lowerTitle, null);
if (album.Any())
try
{
var result = album.Where(x => x.AlbumReleases.Value.Any()).FirstOrDefault();
if (result != null)
var album = SearchForNewAlbum(lowerTitle, null);
if (album.Any())
{
return new List<object> { result };
}
else
{
return new List<object>();
var result = album.Where(x => x.AlbumReleases.Value.Any()).FirstOrDefault();
if (result != null)
{
return new List<object> { result };
}
else
{
return new List<object>();
}
}
}
catch (SkyHookException ex)
{
_logger.Warn(ex, $"Album search failed for '{lowerTitle}'.");
}
catch (Exception ex)
{
_logger.Warn(ex, $"Album search failed for '{lowerTitle}'.");
}
return new List<object>();
}
try
@ -367,8 +407,14 @@ public List<object> SearchForNewEntity(string title)
.Where(x => x != null)
.ToList();
}
catch (HttpException)
catch (HttpException ex)
{
if (ex.Response != null && ex.Response.StatusCode == HttpStatusCode.ServiceUnavailable)
{
_logger.Warn("Entity search failed for '{0}', service temporarily unavailable", title);
return new List<object>();
}
throw new SkyHookException("Search for '{0}' failed. Unable to communicate with LidarrAPI.", title);
}
catch (Exception ex)