Debugging

Flaxon provides a comprehensive debugging system that helps you identify and fix issues quickly.

Debug Mode

from flaxon import Flaxon

app = Flaxon("my-app", debug=True)

# Or via configuration
app = Flaxon("my-app", config={"DEBUG": True})
Warning

Never enable debug=True in production.

Development vs Production Errors

Development Mode

{
  "success": false,
  "error": {
    "code": "FX-DEV-500",
    "message": "division by zero",
    "request_id": "fx_abc123def456",
    "debug": {
      "type": "ZeroDivisionError",
      "traceback": "...",
      "method": "GET",
      "path": "/divide",
      "query": {}
    }
  }
}

Production Mode

{
  "success": false,
  "error": {
    "code": "FX-SRV-500",
    "message": "The request could not be completed.",
    "request_id": "fx_abc123def456"
  }
}

Raising HTTP Exceptions

from flaxon import HTTPException

@app.get("/users/<int:user_id>")
async def get_user(user_id: int):
    if user_id < 0:
        raise HTTPException(400, "Invalid user ID", code="FX-INVALID-ID")

    user = await get_user_by_id(user_id)
    if not user:
        raise HTTPException(404, "User not found", code="FX-USER-404")

    return user

Error Codes

Code Status Description
FX-HTTP-400400Bad Request
FX-HTTP-401401Unauthorized
FX-HTTP-403403Forbidden
FX-HTTP-404404Not Found
FX-HTTP-405405Method Not Allowed
FX-VAL-001422Validation Error
FX-RATE-001429Rate Limit Exceeded
FX-SRV-500500Server Error

Redaction

from flaxon.debugging import redact

data = {
    "username": "alice",
    "password": "secret123",
    "api_key": "key456",
}

safe_data = redact(data)
# {"username": "alice", "password": "[REDACTED]", "api_key": "[REDACTED]"}
Tip

Use /debug/dashboard in development to view error history.