diff --git a/src/iris/poll.ts b/src/iris/poll.ts index 71ab6be..f96718a 100644 --- a/src/iris/poll.ts +++ b/src/iris/poll.ts @@ -15,11 +15,19 @@ export async function fetchFastTransferFeeBps( const url = `${irisBaseUrl(useSandbox)}burn/USDC/fees/${sourceDomain}/${destDomain}`; const res = await fetch(url); if (!res.ok) { - throw new Error(`Iris fees request failed: ${res.status} ${res.statusText}`); + throw new IrisRequestError( + `Iris fees request failed: ${res.status} ${res.statusText}`, + res.status, + ); } const body = (await res.json()) as IrisFeesResponse; const fastEntry = body.find((entry) => entry.finalityThreshold <= 1000); - return fastEntry?.minimumFee ?? 0; + if (!fastEntry) { + throw new IrisRequestError( + `Iris fees response has no fast-transfer tier for domain pair ${sourceDomain} -> ${destDomain}`, + ); + } + return fastEntry.minimumFee; } /** diff --git a/tests/poll.test.ts b/tests/poll.test.ts index e133283..7217c4d 100644 --- a/tests/poll.test.ts +++ b/tests/poll.test.ts @@ -56,25 +56,30 @@ describe("fetchFastTransferFeeBps", () => { expect(feeBps).toBe(2); }); - it("returns 0 when no entry at or under the fast finality threshold exists", async () => { + it("rejects when no entry at or under the fast finality threshold exists", async () => { global.fetch = vi.fn().mockResolvedValue({ ok: true, json: async () => [{ finalityThreshold: 2000, minimumFee: 5 }], }) as unknown as typeof fetch; - const feeBps = await fetchFastTransferFeeBps(26, 27, true); + const err = await fetchFastTransferFeeBps(26, 27, true).catch((e) => e); - expect(feeBps).toBe(0); + expect(err).toBeInstanceOf(IrisRequestError); + expect(err.message).toContain("26 -> 27"); }); - it("throws when the request fails", async () => { + it("throws IrisRequestError with the HTTP status when the request fails", async () => { global.fetch = vi.fn().mockResolvedValue({ ok: false, status: 500, statusText: "Internal Server Error", }) as unknown as typeof fetch; - await expect(fetchFastTransferFeeBps(26, 27, true)).rejects.toThrow("Iris fees request failed"); + const err = await fetchFastTransferFeeBps(26, 27, true).catch((e) => e); + + expect(err).toBeInstanceOf(IrisRequestError); + expect(err.message).toContain("Iris fees request failed"); + expect(err.status).toBe(500); }); });