API Reference

Learn how to handle errors from the do.dev APIs.

Error Response Format

All errors follow this format:

{
  "success": false,
  "error": {
    "code": "error_code",
    "message": "Human readable message",
    "details": {}
  }
}

HTTP Status Codes

CodeDescription
200Success
400Bad Request
401Unauthorized
403Forbidden
404Not Found
409Conflict
422Unprocessable Entity
429Rate Limited
500Internal Error

Error Codes

Authentication Errors

CodeDescription
unauthorizedMissing or invalid auth
token_expiredAccess token expired
insufficient_scopeMissing required scope

Validation Errors

CodeDescription
invalid_requestMalformed request
missing_fieldRequired field missing
invalid_fieldInvalid field value

Resource Errors

CodeDescription
not_foundResource doesn't exist
already_existsResource already exists
conflictResource conflict

Rate Limit Errors

CodeDescription
rate_limitedToo many requests

Billing Errors

CodeDescription
subscription_requiredPaid subscription needed
usage_exceededUsage limit reached
payment_failedPayment unsuccessful

Handling Errors

JavaScript/TypeScript

try {
  const response = await dodev.users.get('user_123');
} catch (error) {
  if (error.code === 'not_found') {
    console.log('User not found');
  } else if (error.code === 'rate_limited') {
    // Wait and retry
    await sleep(error.retryAfter * 1000);
    // Retry request
  } else {
    throw error;
  }
}

With Fetch

const response = await fetch('https://api.do.dev/v1/users/123', {
  headers: { 'Authorization': `Bearer ${apiKey}` },
});

if (!response.ok) {
  const error = await response.json();

  switch (error.error.code) {
    case 'unauthorized':
      // Handle auth error
      break;
    case 'rate_limited':
      // Handle rate limit
      break;
    default:
      throw new Error(error.error.message);
  }
}

Retry Strategy

For transient errors, implement exponential backoff:

async function fetchWithRetry(url: string, options: RequestInit, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      const response = await fetch(url, options);

      if (response.status === 429) {
        const retryAfter = response.headers.get('Retry-After') || '1';
        await sleep(parseInt(retryAfter) * 1000);
        continue;
      }

      return response;
    } catch (error) {
      if (i === maxRetries - 1) throw error;
      await sleep(Math.pow(2, i) * 1000);
    }
  }
}

Getting Help

If you encounter unexpected errors:

  1. Check the error code and message
  2. Review the API documentation
  3. Check the status page
  4. Contact support with the request ID

On this page