Skip to content

Home > @opengovsg/rate-limit > RateLimiter > check

RateLimiter.check() method ​

Consume one point from key's allowance.

Resolves with a RateLimitInfo snapshot when within limits. Throws RateLimitExceededError when the allowance is exhausted. Any other error is reported via logger.error and rethrown as-is, so the caller decides between failing open and failing closed.

Pass a request-scoped logger to attach request identity to anything this call may log. Omit it to fall back to the factory logger.

Signature:

typescript
check(args: {
        key: string;
        logger?: Logger;
    }): Promise<RateLimitInfo>;

Parameters ​

ParameterTypeDescription
args{ key: string; logger?: Logger; }

Returns:

Promise<RateLimitInfo>