FOCUSCurrently working on ScheduleSomething and LayerdEvents algorithmsLearn More
FOCUSCurrently working on ScheduleSomething and LayerdEvents algorithmsLearn More
FOCUSCurrently working on ScheduleSomething and LayerdEvents algorithmsLearn More
FOCUSCurrently working on ScheduleSomething and LayerdEvents algorithmsLearn More
CONTRIBUTING.MdEngineering Handbook
Error Handling & Resiliency
DocsCONTRIBUTING.mdEngineering HandbookError Handling & Resiliency
GitHub Live Sync

Error Handling & Resiliency

Live technical documentation fetched from GitHub repository omghante/metapilot/docs/engineering/error-handling.md

Error Handling Guidelines

Standards for handling exceptions, HTTP status codes, and error payloads across MetaPilot API.

Standard HTTP Status Code Rules

CodeMeaningUsage in MetaPilot
200OKSuccessful GET, PUT, PATCH operations
201CreatedSuccessful POST creation (User, Tenant, Campaign)
204No ContentSuccessful DELETE operations
400Bad RequestValidation errors, invalid payload format
401UnauthorizedMissing or expired JWT access token
403ForbiddenValid JWT, but insufficient role permissions
404Not FoundTarget object does not exist or belongs to another tenant
429Too Many RequestsRate limit exceeded
500Internal Server ErrorUnhandled server exception (logged with stack trace)

Standard Error Response Structure

All DRF error responses return a uniform JSON format:
json
{
  "error": "Short human-readable summary",
  "code": "SPECIFIC_ERROR_CODE",
  "details": {
    "field_name": ["Validation error message"]
  }
}

Exception Handling Best Practices

  1. Catch Specific Exceptions: Always catch specific exceptions (
    ValueError
    ,
    InvalidToken
    ,
    psycopg2.OperationalError
    ) rather than bare
    except:
    .
  2. Log Stack Traces: Log full exception tracebacks before returning 500 error responses:
    python
    logger.error(f"Failed to process campaign broadcast: {exc}", exc_info=True)
    
  3. Environment Safety in Dev: In
    DEBUG=True
    mode, provide fallback defaults for missing dev configurations (such as standard dev Fernet keys) while enforcing strict validation in production.