Errors¶
Every non-success response from DHIS2 raises a typed exception. Dhis2ApiError.web_message exposes the typed envelope when the body is JSON.
errors
¶
Exception hierarchy for dhis2w-client.
Classes¶
Dhis2ClientError
¶
Dhis2ApiError
¶
Bases: Dhis2ClientError
Raised when the DHIS2 API returns a non-success response.
Source code in packages/dhis2w-client/src/dhis2w_client/errors.py
Attributes¶
web_message
property
¶
Parse body as a WebMessageResponse when the shape matches, else None.
DHIS2 returns the envelope on errors too (e.g. 409 on /api/dataValueSets
with status=WARNING + populated conflicts[]), so callers can inspect
import counts and per-row rejections without re-parsing.
Imported lazily because envelopes.py pulls in the generated OAS tree,
which itself imports client.py (for the generated resource
accessors), and client.py imports errors.py — classic cycle. The
web_message call-site runs only after the package is fully loaded,
so the late import is safe.
Functions¶
__init__(status_code, message, body=None)
¶
Capture HTTP status, message, and optional response body.
Source code in packages/dhis2w-client/src/dhis2w_client/errors.py
AuthenticationError
¶
Bases: Dhis2ClientError
Raised when authentication fails or tokens are invalid.
OAuth2FlowError
¶
Bases: Dhis2ClientError
Raised when the OAuth 2.1 authorization-code flow fails.
UnsupportedVersionError
¶
Bases: Dhis2ClientError
Raised when the DHIS2 instance version has no generated client and fallback is disabled.
Source code in packages/dhis2w-client/src/dhis2w_client/errors.py
Functions¶
__init__(version, available)
¶
Capture the reported version and the list of versions we have codegen for.
Source code in packages/dhis2w-client/src/dhis2w_client/errors.py
Functions¶
format_unauthorized_message(method, path, www_authenticate)
¶
Build a 401 message, surfacing actionable hints for known DHIS2 OAuth2 failures.