import MailGlyph, {
ApiError,
AuthenticationError,
MailGlyphError,
NotFoundError,
RateLimitError,
ValidationError
} from 'mailglyph';
const client = new MailGlyph(process.env.MAILGLYPH_SECRET_KEY as string);
try {
await client.contacts.get('missing-contact-id');
} catch (error) {
if (error instanceof NotFoundError) {
console.error('Contact not found');
return;
}
if (error instanceof ValidationError) {
console.error('Validation failed', error.details);
return;
}
if (error instanceof AuthenticationError) {
console.error('Check API key type or value');
return;
}
if (error instanceof RateLimitError) {
console.error('Rate limited, retry after seconds:', error.retryAfter);
return;
}
if (error instanceof ApiError) {
console.error('Server/API error', error.status, error.details);
return;
}
if (error instanceof MailGlyphError) {
console.error('MailGlyph SDK error', error.status, error.message);
return;
}
throw error;
}