Skip to content

Error Rate Simulation #12

Description

@lukehinds

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions