mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Don't throw exception unless needed
This commit is contained in:
parent
e621244405
commit
a9aafbaf5a
@ -611,30 +611,25 @@ namespace Emby.Server.Implementations.LiveTv.Listings
|
|||||||
CancellationToken cancellationToken,
|
CancellationToken cancellationToken,
|
||||||
HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead)
|
HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead)
|
||||||
{
|
{
|
||||||
HttpResponseMessage response = null;
|
var response = await _httpClientFactory.CreateClient(NamedClient.Default)
|
||||||
try
|
.SendAsync(options, completionOption, cancellationToken).ConfigureAwait(false);
|
||||||
|
if (response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
response = await _httpClientFactory.CreateClient(NamedClient.Default)
|
|
||||||
.SendAsync(options, completionOption, cancellationToken).ConfigureAwait(false);
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
catch (HttpRequestException ex)
|
|
||||||
|
// Response is automatically disposed in the calling function,
|
||||||
|
// so dispose manually if not returning.
|
||||||
|
response.Dispose();
|
||||||
|
if (!enableRetry || (int)response.StatusCode >= 500)
|
||||||
{
|
{
|
||||||
response?.Dispose();
|
throw new HttpRequestException(
|
||||||
_tokens.Clear();
|
string.Format(CultureInfo.InvariantCulture, "Request failed: {0}", response.ReasonPhrase),
|
||||||
|
null,
|
||||||
if (!ex.StatusCode.HasValue || (int)ex.StatusCode.Value >= 500)
|
response.StatusCode);
|
||||||
{
|
|
||||||
enableRetry = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!enableRetry)
|
|
||||||
{
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_tokens.Clear();
|
||||||
options.Headers.TryAddWithoutValidation("token", await GetToken(providerInfo, cancellationToken).ConfigureAwait(false));
|
options.Headers.TryAddWithoutValidation("token", await GetToken(providerInfo, cancellationToken).ConfigureAwait(false));
|
||||||
return await Send(options, false, providerInfo, cancellationToken).ConfigureAwait(false);
|
return await Send(options, false, providerInfo, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user