testRateLimitsAreDeliberateErrors
Past its limit, a key is refused with a 429 saying when to try again, an error the runtime sends as it is.
import { HttpError, rateLimit } from "#codebase/tcmts/server"; import assert from "node:assert/strict"; export const testRateLimitsAreDeliberateErrors = () => { rateLimit("server-test", { max: 1, per: 60 }); try { rateLimit("server-test", { max: 1, per: 60 }); assert.fail("allowed twice"); } catch (e) { assert.ok(e instanceof HttpError); assert.equal(e.status, 429); assert.ok(e.retryAfter! >= 1); assert.equal((e as unknown as Record<symbol, unknown>)[Symbol.for("tcm.httpError")], true); } }