Skip to content

Error Handling

All errors return a JSON body with an error code and a human-readable message.

Error Format

json
{
  "error": "address_taken",
  "message": "This email address is already in use"
}
FieldTypeDescription
errorstringMachine-readable error code
messagestringHuman-readable description

HTTP Status Codes

CodeMeaningWhen
200OKSuccessful read or update
201CreatedResource created (account, webhook, etc.)
204No ContentSuccessful delete
400Bad RequestMissing or malformed request body
401UnauthorizedMissing, invalid, or expired token
403ForbiddenQuota or limit exceeded
404Not FoundResource does not exist
409ConflictResource already exists (duplicate address)
410GoneMessage or resource has expired
429Too Many RequestsRate limit exceeded
500Internal Server ErrorUnexpected server error

Common Error Codes

Account Errors

Error CodeStatusDescription
invalid_address400Email address format is invalid
invalid_domain400Domain is not available for registration
password_too_short400Password must be at least 6 characters
address_taken409Email address is already registered
account_limit_reached403Maximum mailbox limit reached
invalid_credentials401Wrong email or password
invalid_token401Token is missing, invalid, or expired

Message Errors

Error CodeStatusDescription
not_found404Message does not exist
expired410Message has been auto-deleted
invalid_index400Attachment index out of range

Pro Errors

Error CodeStatusDescription
domain_limit_reached403Maximum custom domain limit reached
domain_already_exists409Domain already registered
webhook_limit_reached403Maximum webhook limit reached
domain_expired410Domain verification expired

Handling Errors

javascript
const res = await fetch('https://api.mail.cx/api/messages', {
  headers: { 'Authorization': `Bearer ${token}` }
});

if (!res.ok) {
  const body = await res.json();
  console.error(`Error ${res.status}: [${body.error}] ${body.message}`);

  if (res.status === 401) {
    // Token expired — re-authenticate
  } else if (res.status === 429) {
    // Rate limited — wait and retry
  }
}

Mail.cx API Documentation