Skip to content

exceptions

exceptions

The crew_dcs exception hierarchy.

Every error the library raises derives from DomoError, so a single except DomoError catches anything crew_dcs throws — while each subclass tells you which layer failed:

DomoError                    base — carries structured context (this module)
├── AuthError                authentication / token failures
├── RouteError               a Domo API returned an error response
│   ├── <Module>_GET_Error   per-route-module retrieval failures
│   └── <Module>_CRUD_Error  per-route-module write failures
├── TransportError           no HTTP response at all (DNS, TLS, timeout)
└── ClassError               entity-class (curated layer) failures

Defined in crew_dcs.client.get_data (also DomoError subclasses):
├── GetDataError             Domo served an HTML block page (VPN/allowlist)
└── LooperError              reserved for paginated-retrieval failures

What an exception carries

DomoError stores context as plain attributes instead of burying it in a message string: status (HTTP code), entity_id / entity_name, function_name / parent_class (where it was raised), domo_instance, additional_context, and is_warning for non-fatal conditions. Its string representation is assembled from whatever context is present.

RouteError (and AuthError) also keep the failed response as .res — a crew_dcs.client.response.ResponseGetData — and mine it for you: when no explicit message is passed, the constructor pulls message / error / reason out of the API payload and copies status and domo_instance off the response.

Catching

Catch at the granularity you can handle:

from crew_dcs.base.exceptions import DomoError, RouteError
from crew_dcs.routes.access_token import AccessToken_GET_Error, get_access_tokens

try:
    res = await get_access_tokens(auth)
except AccessToken_GET_Error as e:
    # one specific failure mode — full response still attached
    print(e.status, e.res.response)
except RouteError as e:
    # any API-layer failure
    print(e.status, e.message)
except DomoError as e:
    # anything crew_dcs raised, from any layer
    print(e)

TransportError means the request never got a response (network-level), and crew_dcs.client.get_data.GetDataError means Domo served an HTML block page (VPN/allowlist) instead of JSON — both are distinct from a Domo API that answered with an error status, which always surfaces as a RouteError subclass.

AuthError

AuthError(res: Any | None = None, **kwargs)

Bases: DomoError

Exception for authentication-related errors.

Source code in src/crew_dcs/base/exceptions.py
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
def __init__(self, res: Any | None = None, **kwargs):
    self.res = res

    if self.res:
        if not kwargs.get("message"):
            kwargs["message"] = _message_from_response(self.res)

        if not kwargs.get("parent_class"):
            kwargs["parent_class"] = getattr(self.res, "parent_class", None)
        if not kwargs.get("status"):
            kwargs["status"] = getattr(self.res, "status", None)
        if not kwargs.get("domo_instance"):
            auth = getattr(self.res, "auth", None)
            if auth:
                kwargs["domo_instance"] = getattr(auth, "domo_instance", None)

    super().__init__(**kwargs)

ClassError

ClassError(
    cls: Any = None,
    cls_instance: Any = None,
    entity_id_col: str | None = "id",
    **kwargs,
)

Bases: DomoError

Exception for class-specific errors.

Source code in src/crew_dcs/base/exceptions.py
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
def __init__(
    self,
    cls: Any = None,
    cls_instance: Any = None,
    entity_id_col: str | None = "id",
    **kwargs,
):
    self.cls = cls
    self.cls_instance = cls_instance
    self.entity_id_col = entity_id_col

    # Extract class-specific information
    if not kwargs.get("entity_id"):
        kwargs["entity_id"] = self._get_entity_id_str()
    if not kwargs.get("parent_class"):
        kwargs["parent_class"] = self._get_parent_class_str()

    super().__init__(**kwargs)

DomoError

DomoError(
    message: str | None = None,
    exception: Exception | None = None,
    entity_id: str | None = None,
    entity_name: str | None = None,
    function_name: str | None = None,
    parent_class: str | None = None,
    status: int | None = None,
    domo_instance: str | None = None,
    is_warning: bool = False,
    additional_context: dict[str, Any] | None = None,
)

Bases: Exception

Base exception for all Domo-related errors.

This exception stores all relevant context as attributes and provides a clean string representation for logging and debugging.

Source code in src/crew_dcs/base/exceptions.py
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def __init__(
    self,
    message: str | None = None,
    exception: Exception | None = None,
    entity_id: str | None = None,
    entity_name: str | None = None,
    function_name: str | None = None,
    parent_class: str | None = None,
    status: int | None = None,
    domo_instance: str | None = None,
    is_warning: bool = False,
    additional_context: dict[str, Any] | None = None,
):
    self.message = message
    self.exception = exception
    self.entity_id = entity_id
    self.entity_name = entity_name
    self.function_name = function_name
    self.parent_class = parent_class
    self.status = status
    self.domo_instance = domo_instance
    self.is_warning = is_warning
    self.additional_context = additional_context or {}

    if not self.message and not self.exception:
        raise ValueError("Either 'message' or 'exception' must be provided.")

    # Use exception chaining if we have an original exception
    if self.exception:
        # This preserves the full traceback chain
        default_msg = self._generate_default_message
        super().__init__(
            f"{default_msg} (caused by: {type(self.exception).__name__}: {self.exception})"
        )
        # Explicitly set the cause for proper exception chaining
        self.__cause__ = self.exception
    else:
        super().__init__(self._generate_default_message)

RouteError

RouteError(res: Any | None = None, **kwargs)

Bases: DomoError

Exception for API route/endpoint errors.

Source code in src/crew_dcs/base/exceptions.py
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
def __init__(
    self,
    res: (
        Any | None
    ) = None,  # Should be ResponseGetData but avoiding circular import
    **kwargs,
):
    self.res = res

    # Extract information from response if available
    if self.res:
        if not kwargs.get("message"):
            # Try to extract meaningful error message from response
            kwargs["message"] = _message_from_response(self.res)

        if not kwargs.get("parent_class"):
            kwargs["parent_class"] = getattr(self.res, "parent_class", None)
        if not kwargs.get("status"):
            kwargs["status"] = getattr(self.res, "status", None)
        if not kwargs.get("domo_instance"):
            auth = getattr(self.res, "auth", None)
            if auth:
                kwargs["domo_instance"] = getattr(auth, "domo_instance", None)

    # Call parent's __init__
    super().__init__(**kwargs)

TransportError

TransportError(**kwargs)

Bases: DomoError

Exception for client transport failures before an API response exists.

Source code in src/crew_dcs/base/exceptions.py
270
271
def __init__(self, **kwargs):
    super().__init__(**kwargs)