(namespace: RateLimiterNamespace)
| 462 | */ |
| 463 | const counterIncrement = |
| 464 | (namespace: RateLimiterNamespace): RateLimitIncrement => |
| 465 | (organizationId, windowId) => |
| 466 | Effect.tryPromise({ |
| 467 | try: () => { |
| 468 | const stub = namespace.get( |
| 469 | namespace.idFromName(organizationId), |
| 470 | ) as ExecutionRateLimiterStub; |
| 471 | return stub.increment(windowId); |
| 472 | }, |
| 473 | catch: (cause) => { |
| 474 | // oxlint-disable-next-line executor/no-instanceof-error, executor/no-unknown-error-message -- boundary: the Durable Object RPC rejects with a plain platform Error whose message text is the only classification signal Cloudflare gives |
| 475 | const reason = cause instanceof Error ? cause.message : String(cause); |
| 476 | return new RateLimitCounterError({ |
| 477 | organizationId, |
| 478 | code: counterErrorCode(reason), |
| 479 | reason, |
| 480 | cause, |
| 481 | }); |
| 482 | }, |
| 483 | }).pipe( |
| 484 | Effect.tapError((error) => |
| 485 | Effect.annotateCurrentSpan({ |
| 486 | "rate_limit.counter.error_tag": "RateLimitCounterError", |
| 487 | "rate_limit.counter.error_code": error.code, |
| 488 | }), |
| 489 | ), |
| 490 | Effect.withSpan("rate_limit.increment", { |
| 491 | attributes: { "rate_limit.window_id": windowId }, |
| 492 | }), |
| 493 | ); |
| 494 | |
| 495 | /** |
| 496 | * The per-org hourly cap: the `EXECUTION_RATE_LIMIT_PER_HOUR` env override |
no test coverage detected