import Avatcado, {
RateLimitError,
UpstreamError,
AuthenticationError,
ValidationError,
AvatcadoError,
} from "@avatcado/node";
const avatcado = new Avatcado("avat_live_your_api_key");
const { data, error } = await avatcado.vat.validate({ vatNumber: "NL123456789B01" });
if (error) {
if (error instanceof RateLimitError) {
console.log(`Retry after ${error.retryAfter} seconds`);
} else if (error instanceof UpstreamError) {
console.log(`Retry after ${error.retryAfter} seconds`);
} else if (error instanceof AuthenticationError) {
console.log(error.message);
} else if (error instanceof ValidationError) {
console.log(error.message);
console.log(error.details); // Array<{ field, message }> | null
} else {
// AvatcadoError base class
console.log(`${error.code}: ${error.message}`);
console.log(error.docsUrl);
}
}