ItemImageProvider: improve HTTP error handling

pull/6593/head
Bond_009 3 years ago
parent b4c0518001
commit 8fec510971

@ -486,7 +486,20 @@ namespace MediaBrowser.Providers.Manager
try try
{ {
using var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false); 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 using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
await _providerManager.SaveImage( await _providerManager.SaveImage(
@ -500,15 +513,8 @@ namespace MediaBrowser.Providers.Manager
result.UpdateType |= ItemUpdateType.ImageUpdate; result.UpdateType |= ItemUpdateType.ImageUpdate;
return true; 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; break;
} }
} }
@ -588,6 +594,19 @@ namespace MediaBrowser.Providers.Manager
{ {
using var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false); 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 there's already an image of the same size, skip it
if (response.Content.Headers.ContentLength.HasValue) if (response.Content.Headers.ContentLength.HasValue)
{ {
@ -615,15 +634,8 @@ namespace MediaBrowser.Providers.Manager
cancellationToken).ConfigureAwait(false); cancellationToken).ConfigureAwait(false);
result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate; 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; break;
} }
} }

Loading…
Cancel
Save