-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Add ability to randomly return errors to simulate API instability
For example
class ServerSettings:
def __init__(self):
self.error_rate = 0.0 # Probability of returning an error
self.rate_limit_enabled = False
self.requests_per_minute = 60
@app.middleware("http")
async def error_simulation_middleware(request, call_next):
if random.random() < response_config.settings.error_rate:
error_types = [
{"status_code": 429, "detail": "Rate limit exceeded"},
{"status_code": 503, "detail": "Service temporarily unavailable"},
{"status_code": 504, "detail": "Gateway timeout"}
]
error = random.choice(error_types)
raise HTTPException(**error)
response = await call_next(request)
return response
Metadata
Metadata
Assignees
Labels
No labels