using System; using System.Linq; using System.Net.Http; using Microsoft.Net.Http.Headers; using Tgstation.Server.Api.Models.Response; namespace Tgstation.Server.Client { /// /// Occurs when a GitHub rate limit occurs. /// public sealed class RateLimitException : ApiException { /// /// Gets the to try the request again after. /// public DateTimeOffset? RetryAfter { get; } /// /// Initializes a new instance of the class. /// /// The for the . /// The for the . public RateLimitException(ErrorMessageResponse? errorMessage, HttpResponseMessage responseMessage) : base(errorMessage, responseMessage) { if (responseMessage == null) throw new ArgumentNullException(nameof(responseMessage)); if (!responseMessage.Headers.TryGetValues(HeaderNames.RetryAfter, out var values)) return; var secondsString = values.FirstOrDefault(); if (UInt32.TryParse(secondsString, out var seconds)) RetryAfter = DateTimeOffset.UtcNow.AddSeconds(seconds); } /// /// Initializes a new instance of the class. /// public RateLimitException() { } /// /// Initializes a new instance of the class. /// /// The message for the . public RateLimitException(string message) : base(message) { } /// /// Initializes a new instance of the class. /// /// The message for the . /// The inner for the base . public RateLimitException(string message, Exception innerException) : base(message, innerException) { } } }