2020-06-02 22:55:50 +01:00
|
|
|
using System.Globalization;
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
using System;
|
|
|
|
using SpotifyAPI.Web.Http;
|
|
|
|
|
|
|
|
namespace SpotifyAPI.Web
|
|
|
|
{
|
|
|
|
[Serializable]
|
|
|
|
public class APITooManyRequestsException : APIException
|
|
|
|
{
|
|
|
|
public TimeSpan RetryAfter { get; }
|
|
|
|
|
|
|
|
public APITooManyRequestsException(IResponse response) : base(response)
|
|
|
|
{
|
|
|
|
Ensure.ArgumentNotNull(response, nameof(response));
|
|
|
|
|
2020-11-13 13:43:00 +00:00
|
|
|
if (response.Headers.TryGetValue("Retry-After", out string? retryAfter))
|
2020-06-02 22:55:50 +01:00
|
|
|
{
|
|
|
|
RetryAfter = TimeSpan.FromSeconds(int.Parse(retryAfter, CultureInfo.InvariantCulture));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public APITooManyRequestsException() { }
|
|
|
|
|
|
|
|
public APITooManyRequestsException(string message) : base(message) { }
|
|
|
|
|
|
|
|
public APITooManyRequestsException(string message, Exception innerException) : base(message, innerException) { }
|
|
|
|
|
|
|
|
protected APITooManyRequestsException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
|
|
|
}
|
|
|
|
}
|