|
4 | 4 | AuthenticationError, |
5 | 5 | NotFoundError, |
6 | 6 | RateLimitError, |
| 7 | + TemporarilyUnavailableError, |
7 | 8 | RdapApiError, |
8 | 9 | SubscriptionRequiredError, |
9 | 10 | UpstreamError, |
@@ -334,6 +335,40 @@ describe("error handling", () => { |
334 | 335 | } |
335 | 336 | }); |
336 | 337 |
|
| 338 | + it("throws TemporarilyUnavailableError on 503 with retryAfter", async () => { |
| 339 | + const client = new RdapClient("test-key", { baseUrl: BASE_URL }); |
| 340 | + globalThis.fetch = mockFetch( |
| 341 | + { error: "temporarily_unavailable", message: "Data for this domain is temporarily unavailable." }, |
| 342 | + 503, |
| 343 | + { "Retry-After": "300" }, |
| 344 | + ); |
| 345 | + |
| 346 | + try { |
| 347 | + await client.domain("test.com"); |
| 348 | + expect.fail("Should have thrown"); |
| 349 | + } catch (err) { |
| 350 | + expect(err).toBeInstanceOf(TemporarilyUnavailableError); |
| 351 | + expect((err as TemporarilyUnavailableError).retryAfter).toBe(300); |
| 352 | + expect((err as TemporarilyUnavailableError).statusCode).toBe(503); |
| 353 | + } |
| 354 | + }); |
| 355 | + |
| 356 | + it("throws TemporarilyUnavailableError with null retryAfter when header missing", async () => { |
| 357 | + const client = new RdapClient("test-key", { baseUrl: BASE_URL }); |
| 358 | + globalThis.fetch = mockFetch( |
| 359 | + { error: "temporarily_unavailable", message: "Data for this domain is temporarily unavailable." }, |
| 360 | + 503, |
| 361 | + ); |
| 362 | + |
| 363 | + try { |
| 364 | + await client.domain("test.com"); |
| 365 | + expect.fail("Should have thrown"); |
| 366 | + } catch (err) { |
| 367 | + expect(err).toBeInstanceOf(TemporarilyUnavailableError); |
| 368 | + expect((err as TemporarilyUnavailableError).retryAfter).toBeNull(); |
| 369 | + } |
| 370 | + }); |
| 371 | + |
337 | 372 | it("throws UpstreamError on 502", async () => { |
338 | 373 | const client = new RdapClient("test-key", { baseUrl: BASE_URL }); |
339 | 374 | globalThis.fetch = mockFetch( |
|
0 commit comments