ThrottlingException Class
Definition
- Namespace
- Cuemon.AspNetCore.Http.Throttling
- Assemblies
- Cuemon.AspNetCore.dll
The exception that is thrown when a given request threshold has been reached and then throttled.
public class ThrottlingException : TooManyRequestsException, ISerializable
- Inheritance
-
objectThrottlingException
- Implements
- Inherited Members
Examples
The following example demonstrates how a is thrown when a request rate limit has been exceeded.
using System;
using Cuemon.AspNetCore.Http.Throttling;
namespace MyApp.Examples;
public class ThrottlingExceptionExample
{
public void Demonstrate()
{
try
{
// Simulate a rate-limit violation
var resetTime = DateTime.UtcNow.AddMinutes(5);
throw new ThrottlingException(
"API rate limit exceeded.",
rateLimit: 100,
delta: TimeSpan.FromMinutes(5),
reset: resetTime);
}
catch (ThrottlingException ex)
{
Console.WriteLine($"Message: {ex.Message}"); // API rate limit exceeded.
Console.WriteLine($"RateLimit: {ex.RateLimit}"); // 100
Console.WriteLine($"Delta: {ex.Delta.TotalMinutes} minutes"); // 5
Console.WriteLine($"Reset: {ex.Reset}"); // UTC reset time
Console.WriteLine($"StatusCode: {ex.StatusCode}"); // 429
}
}
}
Constructors
| Name | Description |
|---|---|
| ThrottlingException(string, int, TimeSpan, DateTime) | Initializes a new instance of the ThrottlingException class. |
Properties
| Name | Description |
|---|---|
| Delta | Gets the remaining duration of a window. |
| RateLimit | Gets the allowed rate of requests for a given window. |
| Reset | Gets date and time when a window is being reset. |