Skip to main content

Error Response Format

Vouch API errors return a simple error message with the appropriate HTTP status code:
{
  "error": "Human-readable error message"
}
Some errors include additional details:
{
  "error": "Rate limit exceeded",
  "retryAfter": 3600
}

HTTP Status Codes

StatusMeaningWhen It Occurs
400Bad RequestInvalid request parameters
401UnauthorizedInvalid or missing API key
403ForbiddenAPI key lacks permission
402Payment RequiredQuota exceeded
429Too Many RequestsRate limit exceeded
500Internal Server ErrorServer error

Error Codes Reference

Authentication Errors (401)

{
  "error": "Invalid API key"
}
Cause: API key is invalid, expired, or malformed Solution:
  • Verify your API key is correct
  • Check you’re using the right environment (test vs live)
  • Regenerate key if compromised

{
  "error": "Server keys cannot be used in browsers"
}
Cause: Attempting to use server key from browser Solution: Use client key for browser/mobile applications

Request Errors (400)

{
  "error": "Email address is required"
}
Cause: Email parameter missing or empty Solution: Include valid email in request body
{
  "error": "Request body must be valid JSON"
}
Cause: Malformed JSON in request body Solution: Ensure request body is valid JSON
{
  "error": "X-Project-Id header is required"
}
Cause: Missing X-Project-Id header Solution: Include X-Project-Id header in all requests

Permission Errors (403)

{
  "error": "Origin 'https://example.com' not in allowed domains"
}
Cause: Client key used from unauthorized domain Solution: Add domain to allowed list in dashboard
{
  "error": "Project not found or API key lacks access"
}
Cause: Project ID invalid or API key doesn’t have access Solution: Verify project ID and API key match

Quota Errors (402)

{
  "error": "Monthly validation quota exceeded",
  "limit": 10000,
  "used": 10000,
  "remaining": 0,
  "resetAt": "2024-02-01T00:00:00Z"
}
Cause: Monthly validation quota exhausted Solution:
  • Upgrade your plan
  • Wait for quota reset (1st of month)
  • Contact support for quota increase

Rate Limit Errors (429)

{
  "error": "Too many requests. Please try again later.",
  "limit": 5000,
  "window": "1 hour",
  "retryAfter": 3600
}
Cause: Exceeded hourly rate limit Solution:
  • Implement exponential backoff
  • Respect retryAfter value (seconds)
  • Use server keys for higher limits (5,000/hr vs 1,000/hr)

Server Errors (500)

{
  "error": "An internal error occurred. Please try again."
}
Cause: Unexpected server error Solution:
  • Retry with exponential backoff
  • Contact support if persistent

Handling Errors

try {
  const result = await vouch.validate(email);

  // Check recommendation
  if (result.recommendation === 'block') {
    console.log('Email blocked');
    return;
  }

  if (result.recommendation === 'flag') {
    console.log('Email flagged for review');
  }

  // Check specific validations
  if (!result.checks.syntax?.pass) {
    console.log('Invalid email format');
  }

  if (!result.checks.disposable?.pass) {
    console.log('Disposable email not allowed');
  }
} catch (error) {
  // Network or API errors
  console.error('Validation failed:', error.message);
}

Retry Logic

Implement exponential backoff for transient errors:
async function validateWithRetry(email, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      const result = await vouch.validate(email);
      return result;
    } catch (error) {
      // Don't retry on client errors
      if (error.message.includes('Invalid email')) {
        throw error;
      }

      // Last attempt, give up
      if (i === maxRetries - 1) {
        throw error;
      }

      // Exponential backoff
      const delay = Math.pow(2, i) * 1000;
      await new Promise(resolve => setTimeout(resolve, delay));
    }
  }
}

Monitoring Errors

Response Headers

Check these headers to monitor quota and rate limits:
X-Quota-Limit: 10000
X-Quota-Used: 2345
X-Quota-Remaining: 7655
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4876
X-RateLimit-Reset: 1699564800

Logging Recommendations

Log errors with context for debugging:
console.error('Validation failed', {
  email: email,
  errorCode: result.error.code,
  errorMessage: result.error.message,
  projectId: projectId,
  timestamp: new Date().toISOString()
});

Best Practices

const result = await vouch.validate(email);

if (result.recommendation !== 'allow') {
  // Handle blocked or flagged email
  console.log('Email validation failed:', result.recommendation);
  return;
}

// Proceed with valid email
Retry on:
  • RATE_LIMITED (with exponential backoff)
  • INTERNAL_ERROR (max 3 retries)
Don’t retry on:
  • UNAUTHORIZED (fix API key)
  • QUOTA_EXCEEDED (upgrade plan)
  • INVALID_EMAIL (invalid input)
Don’t expose internal error codes to users:
// Good
if (error.code === 'INVALID_EMAIL') {
  showError('Please enter a valid email address');
}

// Bad
showError(`Error: ${error.code} - ${error.message}`);
Set up alerts when quota reaches 80%:
if (quotaUsed / quotaLimit > 0.8) {
  alertAdmins('Vouch quota at 80%. Consider upgrading.');
}

Next Steps