Skip to content

Error Codes

When an API request fails, Universal API returns standardized error codes to help you understand what went wrong. This document provides a comprehensive list of error codes and their meanings.

Error Response Format

When an error occurs, Universal API returns a response with the following structure:

json
{
  "success": false,
  "error": {
    "title": "Error",
    "detail": "Error message describing what went wrong",
    "code": "ERROR_CODE",
    "timestamp": "2025-04-06T22:36:00.000Z"
  },
  "meta": {
    "requestId": "req-1234567890",
    "statusCode": 400,
    "timestamp": "2025-04-06T22:36:00.000Z"
  }
}

The error object contains:

  • title: A general category of the error
  • detail: A specific message describing what went wrong
  • code: A standardized error code that can be used for programmatic handling
  • timestamp: The time when the error occurred

Common Error Codes

Authentication Errors

Error CodeHTTP StatusDescription
UNAUTHORIZED401Authentication credentials are missing or invalid
FORBIDDEN403Authentication succeeded but the user doesn't have permission to access the resource
INVALID_CREDENTIALS401The provided userId or secretUniversalKey is invalid
EXPIRED_TOKEN401The authentication token has expired

Rate Limiting Errors

Error CodeHTTP StatusDescription
RATE_LIMIT_EXCEEDED429The user has exceeded their rate limit
DAILY_LIMIT_EXCEEDED429The anonymous user has exceeded their daily request limit
CREDITS_REQUIRED402The user has no credits remaining for this operation

Resource Errors

Error CodeHTTP StatusDescription
RESOURCE_NOT_FOUND404The requested resource (action, API key, etc.) was not found
ACTION_NOT_FOUND404The specified action ID does not exist
INVALID_ACTION_ID400The action ID format is invalid
ACTION_EXECUTION_ERROR500An error occurred while executing the action

Input Validation Errors

Error CodeHTTP StatusDescription
INVALID_REQUEST400The request format is invalid or missing required fields
INVALID_PARAMETERS400One or more parameters have invalid values
MISSING_REQUIRED_PARAMETER400A required parameter is missing from the request
INVALID_JSON400The request body contains invalid JSON

Server Errors

Error CodeHTTP StatusDescription
INTERNAL_ERROR500An unexpected error occurred on the server
SERVICE_UNAVAILABLE503The service is temporarily unavailable
EXTERNAL_SERVICE_ERROR502An error occurred in an external service
TIMEOUT504The request timed out

Action-Specific Errors

Error CodeHTTP StatusDescription
ACTION_RUNTIME_ERROR500An error occurred in the action runtime
ACTION_TIMEOUT504The action execution timed out
INVALID_ACTION_CODE400The action code is invalid or contains syntax errors
MISSING_API_KEY400A required API key for an external service is missing

Error Handling Best Practices

When handling errors from Universal API:

  1. Check the success field first to determine if the request was successful
  2. Use the code field for programmatic handling rather than parsing the error message
  3. Log the requestId for troubleshooting purposes
  4. Implement appropriate retry logic for rate limiting and server errors
  5. Display user-friendly messages based on the detail field

Example Error Handling

JavaScript Example

javascript
async function executeAction(actionId, params) {
  try {
    const response = await fetch(`https://api.universalapi.co/action/${actionId}`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-Uni-userId': 'your-user-id',
        'X-Uni-secretUniversalKey': 'your-secret-key'
      },
      body: JSON.stringify(params)
    });
    
    const data = await response.json();
    
    if (!data.success) {
      // Handle error based on error code
      switch (data.error.code) {
        case 'RATE_LIMIT_EXCEEDED':
          console.log('Rate limit exceeded. Retrying after delay...');
          // Implement retry logic with exponential backoff
          break;
        case 'ACTION_NOT_FOUND':
          console.error(`Action ${actionId} not found`);
          break;
        case 'INVALID_PARAMETERS':
          console.error(`Invalid parameters: ${data.error.detail}`);
          break;
        default:
          console.error(`Error: ${data.error.detail}`);
      }
      return null;
    }
    
    return data.result;
  } catch (error) {
    console.error('Network error:', error);
    return null;
  }
}

Python Example

python
import requests
import time

def execute_action(action_id, params):
    try:
        response = requests.post(
            f'https://api.universalapi.co/action/{action_id}',
            headers={
                'X-Uni-userId': 'your-user-id',
                'X-Uni-secretUniversalKey': 'your-secret-key'
            },
            json=params
        )
        
        data = response.json()
        
        if not data.get('success'):
            error = data.get('error', {})
            error_code = error.get('code')
            
            # Handle error based on error code
            if error_code == 'RATE_LIMIT_EXCEEDED':
                print('Rate limit exceeded. Retrying after delay...')
                time.sleep(5)  # Wait 5 seconds before retrying
                return execute_action(action_id, params)  # Retry
            elif error_code == 'ACTION_NOT_FOUND':
                print(f'Action {action_id} not found')
            elif error_code == 'INVALID_PARAMETERS':
                print(f'Invalid parameters: {error.get("detail")}')
            else:
                print(f'Error: {error.get("detail")}')
            return None
        
        return data.get('result')
    except Exception as e:
        print(f'Network error: {e}')
        return None

Universal API - The agentic entry point to the universe of APIs