diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index a197e0e18..5074b27b5 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -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> 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 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(); + } + throw new SkyHookException("Search for '{0}' failed. Unable to communicate with LidarrAPI.", title); } catch (Exception ex) @@ -332,25 +346,51 @@ public List SearchForNewEntity(string title) if (IsMbidQuery(lowerTitle)) { - var artist = SearchForNewArtist(lowerTitle); - if (artist.Any()) + List 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 { 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 { result }; - } - else - { - return new List(); + var result = album.Where(x => x.AlbumReleases.Value.Any()).FirstOrDefault(); + if (result != null) + { + return new List { result }; + } + else + { + return new List(); + } } } + 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(); } try @@ -367,8 +407,14 @@ public List 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(); + } + throw new SkyHookException("Search for '{0}' failed. Unable to communicate with LidarrAPI.", title); } catch (Exception ex)