import {
ZendFiError,
AuthenticationError,
PaymentError,
RateLimitError,
isZendFiError,
} from '@zendfi/sdk';
try {
const payment = await zendfi.createPayment({ amount: 49.99 });
} catch (error) {
if (error instanceof AuthenticationError) {
// Re-authenticate or alert the admin
console.error('API key issue:', error.suggestion);
} else if (error instanceof RateLimitError) {
// Back off and retry
console.warn('Rate limited:', error.suggestion);
} else if (error instanceof PaymentError) {
// Show customer-friendly message
console.error('Payment failed:', error.message);
} else if (isZendFiError(error)) {
// Generic ZendFi error
console.error(`[${error.code}] ${error.message}`);
} else {
// Non-ZendFi error
throw error;
}
}