Skip to content

Rapidata error

RapidataError #

RapidataError(
    status_code: Optional[int] = None,
    message: str | None = None,
    original_exception: Exception | None = None,
    details: Any = None,
    trace_id: str | None = None,
)

Bases: Exception

Custom error class for Rapidata API errors.

Source code in src/rapidata/rapidata_client/exceptions/rapidata_error.py
def __init__(
    self,
    status_code: Optional[int] = None,
    message: str | None = None,
    original_exception: Exception | None = None,
    details: Any = None,
    trace_id: str | None = None,
):
    self.status_code = status_code
    self.message = message
    self.original_exception = original_exception
    self.details = details
    # Header first: it carries the bare trace id, while the problem+json
    # body carries the full traceparent (00-<trace>-<span>-<flags>). Taking
    # the header first keeps the id in one searchable shape no matter which
    # layer produced the error — a timeout that never reached a handler has
    # no body at all, only the header.
    self.trace_id = trace_id or self._trace_id_from_details(details)

    # Create a nice error message
    error_msg = "Rapidata API Error"
    if status_code:
        error_msg += f" ({status_code})"
    if message:
        error_msg += f": {message}"

    super().__init__(error_msg)

get_reason #

get_reason() -> str

Get a concise reason string suitable for grouping and display.

Returns the most meaningful error reason extracted from the API response.

Source code in src/rapidata/rapidata_client/exceptions/rapidata_error.py
def get_reason(self) -> str:
    """Get a concise reason string suitable for grouping and display.

    Returns the most meaningful error reason extracted from the API response.
    """
    if self.details and isinstance(self.details, dict):
        title = self.details.get("title")
        if title:
            return title

    if self.message:
        return self.message

    return "Unknown error"