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-400 | 400 | Bad Request |
| FX-HTTP-401 | 401 | Unauthorized |
| FX-HTTP-403 | 403 | Forbidden |
| FX-HTTP-404 | 404 | Not Found |
| FX-HTTP-405 | 405 | Method Not Allowed |
| FX-VAL-001 | 422 | Validation Error |
| FX-RATE-001 | 429 | Rate Limit Exceeded |
| FX-SRV-500 | 500 | Server 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.