rate-limit-rejector
The internal:rate-limit-rejector interceptor rejects requests with 429 Too Many Requests when the gateway’s rate limit counter reports the limit has been exceeded.
It is designed for use with enforce: false rate limit configurations, where the gateway counts and populates rate limit data but does not enforce natively. This interceptor provides the enforcement step.
Registration
Section titled “Registration”actions: - target: "$.paths[*].get" update: x-plenum-interceptor: - module: "internal:rate-limit-rejector" hook: on_request function: checkRateLimit| Hook | Function | Can short-circuit |
|---|---|---|
on_request | checkRateLimit | Yes |
Options
Section titled “Options”No configuration options. The interceptor reads rate limit state from the gateway-provided input.rateLimits object.
The interceptor reads input.rateLimits, a gateway-populated object:
| Field | Type | Description |
|---|---|---|
over | boolean | true when the rate limit has been exceeded |
The rateLimits object is only populated when rate limit configuration is active on the upstream.
Behaviour
Section titled “Behaviour”- If
rateLimitsis missing orrateLimits.overisfalse, the request continues to the upstream. - If
rateLimits.overistrue, the interceptor short-circuits with429.
Error response
Section titled “Error response”{ "error": "rate limit exceeded"}Status code 429.
Why use enforce: false?
Section titled “Why use enforce: false?”With enforce: false, the gateway counts rate limits but does not reject requests. This allows custom logic (logging, metrics, header injection) to run in earlier interceptors before the rejector fires:
x-plenum-interceptor: - module: "./interceptors/log-rate-limit.js" hook: on_request function: logRateLimit - module: "internal:rate-limit-rejector" hook: on_request function: checkRateLimitThe log interceptor can inspect input.rateLimits and emit metrics, then the rejector enforces. The order of interceptors in the array controls execution order.
See also
Section titled “See also”- Interceptors overview — writing and ordering interceptors