Skip to content

Commit 405b721

Browse files
committed
Raise RateLimitError on CDX API 503 responses
Fixes #5. CdxApi#cdx_get now raises RateLimitError instead of generic Error when the CDX Server returns HTTP 503, consistent with SaveApi's rate-limit handling.
1 parent 381ee65 commit 405b721

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/archaeo/cdx_api.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ def cdx_get(params)
151151
)
152152
return response if response.status == 200
153153

154+
if response.status == 503
155+
raise RateLimitError,
156+
"CDX API rate limited (HTTP 503)"
157+
end
158+
154159
raise Error, "CDX API returned HTTP #{response.status}"
155160
end
156161

spec/archaeo/cdx_api_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ def cdx_json_response(rows, resume_key: nil)
199199
end
200200
end
201201

202+
context "with rate limit (503)" do
203+
let(:fake_client) do
204+
FakeHttpClient.new([FakeHttpClient.response(status: 503)])
205+
end
206+
207+
it "raises RateLimitError" do
208+
expect { client.snapshots("example.com").to_a }
209+
.to raise_error(Archaeo::RateLimitError, /rate limited/)
210+
end
211+
end
212+
202213
context "with invalid match_type" do
203214
let(:fake_client) { FakeHttpClient.new([]) }
204215

0 commit comments

Comments
 (0)