diff options
Diffstat (limited to 'src/Cepis/RateLimitedException.cs')
| -rw-r--r-- | src/Cepis/RateLimitedException.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/Cepis/RateLimitedException.cs b/src/Cepis/RateLimitedException.cs new file mode 100644 index 0000000..da1e04c --- /dev/null +++ b/src/Cepis/RateLimitedException.cs @@ -0,0 +1,39 @@ +namespace Cepis; + +/// <summary> +/// The API, or the edge in front of it, answered 429 on every attempt. +/// </summary> +public sealed class RateLimitedException : CepisException +{ + /// <summary>Create the exception with a message and the wait requested.</summary> + /// <param name="message">what went wrong</param> + /// <param name="retryAfter"> + /// what the server asked for, or <see langword="null"/> if it did not say + /// </param> + public RateLimitedException(string message, TimeSpan? retryAfter = null) + : base(message) + { + RetryAfter = retryAfter; + } + + /// <summary>Create the exception with a message, the wait and a cause.</summary> + /// <param name="message">what went wrong</param> + /// <param name="retryAfter">what the server asked for, if anything</param> + /// <param name="innerException">the failure underneath</param> + public RateLimitedException(string message, TimeSpan? retryAfter, Exception? innerException) + : base(message, innerException) + { + RetryAfter = retryAfter; + } + + /// <summary> + /// How long the server asked the caller to wait, or <see langword="null"/> + /// if it did not say. + /// </summary> + /// <remarks> + /// The client already honoured this across the attempts it made, capped at + /// <see cref="CepisClientOptions.BackoffMax"/>. It is exposed here for + /// callers who want to reschedule the work. + /// </remarks> + public TimeSpan? RetryAfter { get; } +} |