1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2025-01-18 21:29:46 +00:00
Sonarr/src/NzbDrone.Common/Http/TooManyRequestsException.cs
2016-12-23 13:45:24 -08:00

29 lines
886 B
C#

using System;
namespace NzbDrone.Common.Http
{
public class TooManyRequestsException : HttpException
{
public TimeSpan RetryAfter { get; private set; }
public TooManyRequestsException(HttpRequest request, HttpResponse response)
: base(request, response)
{
if (response.Headers.ContainsKey("Retry-After"))
{
var retryAfter = response.Headers["Retry-After"].ToString();
int seconds;
DateTime date;
if (int.TryParse(retryAfter, out seconds))
{
RetryAfter = TimeSpan.FromSeconds(seconds);
}
else if (DateTime.TryParse(retryAfter, out date))
{
RetryAfter = date.ToUniversalTime() - DateTime.UtcNow;
}
}
}
}
}