ClawdMaildocs

Error Handling

Understanding API error responses.

Error Format

When a request fails, the API returns a consistent JSON error object. The type field identifies the category, message provides a human-readable explanation, and the optional param field indicates which parameter caused the issue.

{
  "error": {
    "type": "invalid_request",
    "message": "The 'email' field is required.",
    "param": "email"
  }
}

Error Types

TypeStatusDescription
invalid_request400The request was malformed or missing required parameters. Check the error message for details on which field failed validation.
auth_error401No valid API key was provided. Ensure your Authorization header includes a valid Bearer token.
forbidden403The API key doesn't have permission to perform the requested action. Check your key's scopes.
not_found404The requested resource doesn't exist. Verify the ID or path is correct.
rate_limit429Too many requests. Back off and retry after the time indicated in the Retry-After header.
server_error500Something went wrong on our end. These are rare — if persistent, contact support.

Handling Errors

Always check the HTTP status code and parse the error body. Here’s a recommended pattern for handling errors in your integration:

const response = await fetch('https://app.clawdmail.ai/api/v1/campaigns', {
  headers: { 'Authorization': 'Bearer cm_live_your_key' },
});

if (!response.ok) {
  const { error } = await response.json();
  switch (error.type) {
    case 'auth_error':
      throw new Error('Invalid API key');
    case 'rate_limit':
      const retryAfter = response.headers.get('Retry-After');
      await sleep(Number(retryAfter) * 1000);
      break;
    default:
      throw new Error(error.message);
  }
}

const { data } = await response.json();