Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.0 KB
Raw Blame
from rest_framework import status
from rest_framework.exceptions import APIException


class EndpointQueryTooExpensive(APIException):
    """A customer query hit a ClickHouse cost guardrail — deterministic, so 400 (not a retry-inviting 5xx)."""

    status_code = status.HTTP_400_BAD_REQUEST
    default_code = "query_performance_limit"
    default_detail = "This query is too expensive to run inline. Narrow its scope or materialize the endpoint."


class EndpointAtCapacity(APIException):
    """Shared ClickHouse pool momentarily at capacity — transient; materializing gives isolated compute."""

    wait: int
    status_code = status.HTTP_503_SERVICE_UNAVAILABLE
    default_code = "query_capacity"
    default_detail = (
        "Queries are momentarily at capacity — please retry shortly. For consistently heavy "
        "endpoints, materialize to run on dedicated endpoint compute that isn't affected by shared query load."
    )

    def __init__(self, *, wait: int) -> None:
        super().__init__()
        self.wait = wait