Commit d69e59c
feat: add HTTP 429 rate limit retry support (#83)
* feat: Add HTTP 429 rate limiting support with automatic retry
- Add LagoRateLimitError class for 429 responses
- Parse x-ratelimit-* headers from responses
- Implement automatic retry on 429 with configurable max retries
- Support header-based reset timing and exponential backoff
- Create fetch wrapper to intercept and handle rate limiting
- Add LagoClientConfig with rateLimitRetry options
- Include comprehensive tests for all rate limiting features
- Add RATE_LIMITING.md documentation
- Add rate_limiting_example.ts with usage patterns
- Maintain backward compatibility with existing API
- Do not modify generated OpenAPI code
* fix: correct rate limit test setup
* fix: replace broken mock_fetch with simple fetch mock
mock_fetch library's URLPattern is incompatible with current Deno.
Replace with a lightweight createMockFetch helper.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* chore: gitignore ARCHITECTURE.md
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* chore: update deno.lock
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: implement real exponential backoff, remove dead code and generated docs
- Fix getWaitTime to actually fall back to exponential backoff
(1s, 2s, 4s...) when x-ratelimit-reset header is missing.
Previously always used error.retryAfter which defaulted to 60s,
meaning every retry without a header waited a full minute.
- Change missing-header default from 60 to -1 so the backoff path
is triggered correctly.
- Remove RateLimitRetryHandler class (rate_limit_retry.ts) — both
branches of handleResponse() threw unconditionally, making the
retryOnRateLimit flag a no-op. The class was never used by
createRateLimitFetch. Remove its export from mod.ts.
- Remove RATE_LIMITING.md (394 lines) and examples/rate_limiting_example.ts
(305 lines of commented-out code).
- Add test verifying exponential backoff triggers ~1s wait (not 60s)
when reset header is absent.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* chore: remove deno.lock incompatible with CI Deno v1.x
Local Deno generated lockfile v5 which is unsupported by CI's
Deno 1.46.3. Removing so CI can regenerate.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* chore: add .claude to .gitignore
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: add 20s max retry delay cap
Prevents excessively long waits when the server returns a large
x-ratelimit-reset value. Applies to both header-based and
exponential backoff delays.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: remove deno.lock and add to .gitignore
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Lago Developer <dev@lago.io>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 5fbe72b commit d69e59c
7 files changed
Lines changed: 469 additions & 129 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
3 | 23 | | |
4 | | - | |
5 | 24 | | |
6 | 25 | | |
7 | 26 | | |
8 | 27 | | |
9 | 28 | | |
10 | 29 | | |
11 | 30 | | |
12 | | - | |
| 31 | + | |
| 32 | + | |
13 | 33 | | |
14 | 34 | | |
15 | 35 | | |
| |||
42 | 62 | | |
43 | 63 | | |
44 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
45 | 70 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
0 commit comments