Skip to main content

Error Handling

Learn how to handle errors gracefully in Magical Auth.

Common Error Codes

Error CodeStatusDescription
CARRIER_NOT_ELIGIBLE422Carrier doesn't support Magical Auth
INVALID_PHONE_NUMBER400Phone number format is invalid
SESSION_EXPIRED404Session has expired
RATE_LIMIT_EXCEEDED429Too many requests

Error Handling Example

try {
const result = await glide.magicAuth.getPhoneNumber();
} catch (error) {
switch (error.code) {
case 'CARRIER_NOT_ELIGIBLE':
// Offer SMS fallback
showSMSVerification();
break;
case 'SESSION_EXPIRED':
// Retry the request
retryVerification();
break;
default:
console.error('Unexpected error:', error);
}
}

Best Practices

  1. Always provide user-friendly error messages
  2. Implement fallback mechanisms for unsupported carriers
  3. Log errors for debugging
  4. Retry transient failures with exponential backoff