mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Retry http extension
This commit is contained in:
28
src/Jackett/HttpClientExtensions.cs
Normal file
28
src/Jackett/HttpClientExtensions.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jackett
|
||||
{
|
||||
public static class HttpClientExtensions
|
||||
{
|
||||
public static async Task<string> GetStringAsync(this HttpClient client, string uri, int retries)
|
||||
{
|
||||
Exception exception = null;
|
||||
try
|
||||
{
|
||||
return await client.GetStringAsync(uri);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
exception = ex;
|
||||
}
|
||||
if (retries > 0)
|
||||
return await client.GetStringAsync(uri, --retries);
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user