Skip to content

Errors & requests

Non-2xx HTTP responses throw FrankfurterError.

Read-only fields:

FieldMeaning
statusHTTP status code
statusTextStatus text from the response
urlRequest URL
bodyParsed JSON body when possible, otherwise undefined
headersResponse 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.

const client = new FrankfurterClient({
timeout: 5_000,
});

Per-call cancellation or deadlines:

const controller = new AbortController();
const rates = await client.latest(
{ base: "EUR", quotes: ["USD"] },
{ signal: controller.signal },
);
const client = new FrankfurterClient({
fetch: window.fetch.bind(window),
});
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.