getCurrentWindow method
FutureOr<RateLimitingWindow<Id> >
getCurrentWindow(
- RequestContext req,
- ResponseContext res,
- DateTime currentTime
override
Computes the current window in which the user is acting.
For example, if your API was limited to 1000 requests/hour, then you would return a window containing the current hour, and the number of requests the user has sent in the past hour.
Implementation
@override
FutureOr<RateLimitingWindow<Id>> getCurrentWindow(
RequestContext req, ResponseContext res, DateTime currentTime) async {
var id = await getId(req, res);
try {
var data = await service.read(id);
return RateLimitingWindow.fromJson(data);
} catch (e) {
if (e is AngelHttpException) {
if (e.statusCode == 404) {
} else {
rethrow;
}
} else {
rethrow;
}
}
var window = RateLimitingWindow(id, currentTime, 0);
await updateCurrentWindow(req, res, window, currentTime);
return window;
}