"""Domain errors shared by the reusable service layer. Services are transport-agnostic: they raise :class:`ServiceError` carrying a stable ``code`` and an HTTP ``status`` hint. The REST layer maps it to an ``HTTPException`` (via the global handler in ``backend.main``) while the tool layer maps it to a :class:`backend.tools.context.ToolError`. """ from __future__ import annotations from typing import Any class ServiceError(Exception): """Base error for the shared business-logic services.""" def __init__( self, message: str, *, code: str = "service_error", status: int = 400, details: dict[str, Any] | None = None, ): super().__init__(message) self.message = message self.code = code self.status = status self.details = details or {}