rejectRequest method
FutureOr<Object>
rejectRequest(
- RequestContext req,
- ResponseContext res,
- RateLimitingWindow<
User> window, - 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);
}