Errors & requests
FrankfurterError
Section titled “FrankfurterError”Non-2xx HTTP responses throw FrankfurterError.
Read-only fields:
| Field | Meaning |
|---|---|
status | HTTP status code |
statusText | Status text from the response |
url | Request URL |
body | Parsed JSON body when possible, otherwise undefined |
headers | Response Headers or undefined |
import { FrankfurterClient, FrankfurterError } from "frankfurter-js";
const client = new FrankfurterClient();
try { await client.historical("invalid-date");} catch (error) { if (error instanceof FrankfurterError) { console.error(error.status, error.statusText, error.url, error.body); } else { throw error; }}If fetch is missing from the environment and not passed in client options, the client throws a plain Error at construction time.
Timeout
Section titled “Timeout”const client = new FrankfurterClient({ timeout: 5_000,});AbortSignal
Section titled “AbortSignal”Per-call cancellation or deadlines:
const controller = new AbortController();
const rates = await client.latest( { base: "EUR", quotes: ["USD"] }, { signal: controller.signal },);Custom fetch
Section titled “Custom fetch”const client = new FrankfurterClient({ fetch: window.fetch.bind(window),});Self-hosted base URL
Section titled “Self-hosted base URL”const client = new FrankfurterClient({ baseUrl: "https://rates.example.com",});The client ensures requests go to the /v2 API prefix unless your baseUrl already ends with /v2.