Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Rate Simulation #12

Open
lukehinds opened this issue Feb 16, 2025 · 0 comments
Open

Error Rate Simulation #12

lukehinds opened this issue Feb 16, 2025 · 0 comments

Comments

@lukehinds
Copy link
Collaborator

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant