ItemImageProvider: improve HTTP error handling
This commit is contained in:
parent
b4c0518001
commit
8fec510971
|
@ -486,7 +486,20 @@ namespace MediaBrowser.Providers.Manager
|
|||
try
|
||||
{
|
||||
using var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
// Sometimes providers send back bad url's. Just move to the next image
|
||||
if (response.StatusCode == HttpStatusCode.NotFound || response.StatusCode == HttpStatusCode.Forbidden)
|
||||
{
|
||||
_logger.LogDebug("{Url} returned {StatusCode}, ignoring", url, response.StatusCode);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
_logger.LogWarning("{Url} returned {StatusCode}, skipping all remaining requests", url, response.StatusCode);
|
||||
break;
|
||||
}
|
||||
|
||||
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
await _providerManager.SaveImage(
|
||||
|
@ -500,15 +513,8 @@ namespace MediaBrowser.Providers.Manager
|
|||
result.UpdateType |= ItemUpdateType.ImageUpdate;
|
||||
return true;
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
// Sometimes providers send back bad url's. Just move to the next image
|
||||
if (ex.StatusCode.HasValue
|
||||
&& (ex.StatusCode.Value == HttpStatusCode.NotFound || ex.StatusCode.Value == HttpStatusCode.Forbidden))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -588,6 +594,19 @@ namespace MediaBrowser.Providers.Manager
|
|||
{
|
||||
using var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// Sometimes providers send back bad url's. Just move to the next image
|
||||
if (response.StatusCode == HttpStatusCode.NotFound || response.StatusCode == HttpStatusCode.Forbidden)
|
||||
{
|
||||
_logger.LogDebug("{Url} returned {StatusCode}, ignoring", url, response.StatusCode);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
_logger.LogWarning("{Url} returned {StatusCode}, skipping all remaining requests", url, response.StatusCode);
|
||||
break;
|
||||
}
|
||||
|
||||
// If there's already an image of the same size, skip it
|
||||
if (response.Content.Headers.ContentLength.HasValue)
|
||||
{
|
||||
|
@ -615,15 +634,8 @@ namespace MediaBrowser.Providers.Manager
|
|||
cancellationToken).ConfigureAwait(false);
|
||||
result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate;
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
// Sometimes providers send back bad urls. Just move onto the next image
|
||||
if (ex.StatusCode.HasValue
|
||||
&& (ex.StatusCode.Value == HttpStatusCode.NotFound || ex.StatusCode.Value == HttpStatusCode.Forbidden))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user