RateLimiterConfig constructor

RateLimiterConfig({
  1. required String domain,
  2. required String source,
  3. required int maxAttempts,
  4. Duration? timeframe,
  5. Map<String, String>? defaultExtraData,
  6. Future<void> onRateLimitExceeded(
    1. Session session,
    2. String key
    )?,
})

Creates the configuration for a RateLimiter.

Throws ArgumentError for non-positive limits or windows.

Implementation

RateLimiterConfig({
  required this.domain,
  required this.source,
  required this.maxAttempts,
  this.timeframe,
  this.defaultExtraData,
  this.onRateLimitExceeded,
}) {
  if (maxAttempts <= 0) {
    throw ArgumentError.value(maxAttempts, 'maxAttempts', 'Must be positive');
  }
  if (timeframe != null && timeframe! <= Duration.zero) {
    throw ArgumentError.value(timeframe, 'timeframe', 'Must be positive');
  }
}