rejectRequest method

FutureOr<Object> rejectRequest(
  1. RequestContext req,
  2. ResponseContext res,
  3. RateLimitingWindow<User> window,
  4. DateTime currentTime,
)

Signals to a user that they have exceeded the rate limit for the current window, and terminates execution of the current RequestContext.

The default implementation is throw an AngelHttpException with status code 429 and the given errorMessage, as well as sending a Retry-After header, and then returning false.

Whatever is returned here will be returned in handleRequest.

Implementation

FutureOr<Object> rejectRequest(RequestContext req, ResponseContext res,
    RateLimitingWindow<User> window, DateTime currentTime) {
  var retryAfter = window.resetTime!.difference(currentTime);
  res.headers['retry-after'] = retryAfter.inSeconds.toString();
  throw AngelHttpException(message: errorMessage, statusCode: 429);
}