mirror of
https://github.com/Lidarr/Lidarr
synced 2025-12-06 08:25:54 +01:00
Fixed: Improve error handling for fingerprint search API failures
This commit is contained in:
parent
3dabcab134
commit
19a1d5c62d
1 changed files with 27 additions and 10 deletions
|
|
@ -328,19 +328,36 @@ public List<Album> SearchForNewAlbum(string title, string artist)
|
||||||
|
|
||||||
public List<Album> SearchForNewAlbumByRecordingIds(List<string> recordingIds)
|
public List<Album> SearchForNewAlbumByRecordingIds(List<string> recordingIds)
|
||||||
{
|
{
|
||||||
var ids = recordingIds.Where(x => x.IsNotNullOrWhiteSpace()).Distinct();
|
try
|
||||||
var httpRequest = _requestBuilder.GetRequestBuilder().Create()
|
{
|
||||||
.SetSegment("route", "search/fingerprint")
|
var ids = recordingIds.Where(x => x.IsNotNullOrWhiteSpace()).Distinct();
|
||||||
.Build();
|
var httpRequest = _requestBuilder.GetRequestBuilder().Create()
|
||||||
|
.SetSegment("route", "search/fingerprint")
|
||||||
|
.Build();
|
||||||
|
|
||||||
httpRequest.SetContent(ids.ToJson());
|
httpRequest.SetContent(ids.ToJson());
|
||||||
httpRequest.Headers.ContentType = "application/json";
|
httpRequest.Headers.ContentType = "application/json";
|
||||||
|
|
||||||
var httpResponse = _httpClient.Post<List<AlbumResource>>(httpRequest);
|
var httpResponse = _httpClient.Post<List<AlbumResource>>(httpRequest);
|
||||||
|
|
||||||
return httpResponse.Resource.Select(MapSearchResult)
|
return httpResponse.Resource.Select(MapSearchResult)
|
||||||
.Where(x => x != null)
|
.Where(x => x != null)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
}
|
||||||
|
catch (HttpException ex)
|
||||||
|
{
|
||||||
|
if (ex.Response != null && ex.Response.StatusCode == HttpStatusCode.ServiceUnavailable)
|
||||||
|
{
|
||||||
|
throw new SkyHookException("Search by fingerprint failed. LidarrAPI Temporarily Unavailable (503)");
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new SkyHookException("Search by fingerprint failed. Unable to communicate with LidarrAPI. {0}", ex, ex.Message);
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (ex is not SkyHookException)
|
||||||
|
{
|
||||||
|
_logger.Warn(ex, ex.Message);
|
||||||
|
throw new SkyHookException("Search by fingerprint failed. Invalid response received from LidarrAPI.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<object> SearchForNewEntity(string title)
|
public List<object> SearchForNewEntity(string title)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue