diff --git a/Makefile b/Makefile index 44199243..a6f3f70b 100644 --- a/Makefile +++ b/Makefile @@ -3,5 +3,5 @@ docs: poetry install --with dev poetry run sphinx-apidoc -o docs src/imednet \ - src/imednet/core/__init__.py src/imednet/models/base.py + src/imednet/errors/__init__.py src/imednet/models/base.py poetry run sphinx-build -b html --keep-going docs docs/_build/html diff --git a/docs/api_overview.rst b/docs/api_overview.rst index 538d1ba6..8020b81f 100644 --- a/docs/api_overview.rst +++ b/docs/api_overview.rst @@ -29,12 +29,12 @@ HTTP methods and errors The API primarily supports ``GET`` and ``POST`` requests. Non‐successful status codes raise typed exceptions: -* ``400`` – :class:`~imednet.core.exceptions.ValidationError` -* ``401`` – :class:`~imednet.core.exceptions.AuthenticationError` -* ``403`` – :class:`~imednet.core.exceptions.AuthorizationError` -* ``404`` – :class:`~imednet.core.exceptions.NotFoundError` -* ``429`` – :class:`~imednet.core.exceptions.RateLimitError` -* ``5xx`` – :class:`~imednet.core.exceptions.ServerError` +* ``400`` – :class:`~imednet.errors.ValidationError` +* ``401`` – :class:`~imednet.errors.AuthenticationError` +* ``403`` – :class:`~imednet.errors.AuthorizationError` +* ``404`` – :class:`~imednet.errors.NotFoundError` +* ``429`` – :class:`~imednet.errors.RateLimitError` +* ``5xx`` – :class:`~imednet.errors.ServerError` See :doc:`retry_policy` for examples of handling these errors and configuring custom retry logic. diff --git a/docs/imednet.core.rst b/docs/imednet.core.rst index 40790e7e..4443ad75 100644 --- a/docs/imednet.core.rst +++ b/docs/imednet.core.rst @@ -59,13 +59,6 @@ HTTPX requests used by the SDK: :show-inheritance: :noindex: -imednet.core.exceptions module ------------------------------- - -.. automodule:: imednet.core.exceptions - :members: - :undoc-members: - :show-inheritance: imednet.core.paginator module ----------------------------- @@ -87,7 +80,7 @@ requests should be retried. The SDK uses from imednet.core.client import Client from imednet.core.retry import RetryPolicy, RetryState - from imednet.core.exceptions import ServerError + from imednet.errors import ServerError class ServerRetry(RetryPolicy): def should_retry(self, state: RetryState) -> bool: diff --git a/docs/quick_start.rst b/docs/quick_start.rst index 820b58d7..e2863449 100644 --- a/docs/quick_start.rst +++ b/docs/quick_start.rst @@ -47,7 +47,7 @@ Custom retry logic can be provided via a ``RetryPolicy``: .. code-block:: python from imednet.core.retry import RetryPolicy, RetryState - from imednet.core.exceptions import ServerError + from imednet.errors import ServerError class ServerRetry(RetryPolicy): def should_retry(self, state: RetryState) -> bool: diff --git a/docs/retry_policy.rst b/docs/retry_policy.rst index 2a060b32..97ea02b4 100644 --- a/docs/retry_policy.rst +++ b/docs/retry_policy.rst @@ -13,7 +13,7 @@ Use typed exceptions to respond to different failure modes: .. code-block:: python from imednet import ImednetSDK - from imednet.core.exceptions import RateLimitError, ServerError, NotFoundError + from imednet.errors import RateLimitError, ServerError, NotFoundError sdk = ImednetSDK() try: @@ -35,7 +35,7 @@ Retry policies decide if a request should be retried. To retry on from imednet.core.client import Client from imednet.core.retry import RetryPolicy, RetryState - from imednet.core.exceptions import RateLimitError, ServerError + from imednet.errors import RateLimitError, ServerError class RateLimitServerRetry(RetryPolicy): def should_retry(self, state: RetryState) -> bool: diff --git a/docs/schema_validation.rst b/docs/schema_validation.rst index 3c4a3358..118fbfb3 100644 --- a/docs/schema_validation.rst +++ b/docs/schema_validation.rst @@ -7,7 +7,7 @@ submitting it to the API. The validator checks that all variables exist, required fields are present, and that values match the expected types. If the variable metadata for a form is missing, ``SchemaValidator`` automatically loads it from the API using :class:`~imednet.endpoints.variables.VariablesEndpoint`. -Any problems raise :class:`~imednet.core.exceptions.ValidationError` before the +Any problems raise :class:`~imednet.errors.ValidationError` before the record is sent to the server. ``SchemaValidator`` works with both synchronous and asynchronous SDK clients. diff --git a/examples/custom_retry.py b/examples/custom_retry.py index 64f15288..ff7ba241 100644 --- a/examples/custom_retry.py +++ b/examples/custom_retry.py @@ -6,9 +6,10 @@ import httpx +from imednet.auth.strategy import AuthStrategy from imednet.core.client import Client -from imednet.core.exceptions import RateLimitError, ServerError from imednet.core.retry import RetryPolicy, RetryState +from imednet.errors import RateLimitError, ServerError from imednet.utils import configure_json_logging """Demonstrate custom retry logic with simulated rate limit and server errors. @@ -49,14 +50,13 @@ def responder(_: httpx.Request) -> httpx.Response: class MockClient(Client): - def _create_client(self, api_key: str, security_key: str) -> httpx.Client: # type: ignore[override] + def _create_client(self, auth: AuthStrategy) -> httpx.Client: # type: ignore[override] return httpx.Client( base_url=self.base_url, headers={ "Accept": "application/json", "Content-Type": "application/json", - "x-api-key": api_key, - "x-imn-security-key": security_key, + **auth.get_headers(), }, timeout=self.timeout, transport=httpx.MockTransport(responder),