Open headlessme opened 1 year ago
Typically, if you already know the value of force
at call-time, then you should be able to interpret the result resolved from use()
in the same way. For instance:
async function checkLimitForRoute(route, uid, cost) {
const force = FORCE_ROUTES.includes(route);
const limit = await limiter.use(uid, cost);
// ...
if (limit.rejected && !force) {
// reject request
} else {
// allow request
}
}
We have some endpoints that are rate limited but we always want to the requests to succeed even if that sends the token balance negative. Currently we'd need to instantiate two
RollingLimit
classes with different options and manage which instance was applied to the different endpoints. Would you be open to adding a new parameter to the use() signature to specify the value for force? e.g.use(id, cost, force)