Guides

Handle errors

Every failure raises a subclass of OvokError. Catch the specific class you can act on and

  • Stable unknown
  • Release candidate since 0.1.0-rc.3
  • Development since 0.1.0-dev.21+c43ebba

Every failure raises a subclass of OvokError. Catch the specific class you can act on and let the rest propagate.

ErrorWhen
OvokValidationErrorThe request was malformed or invalid (400, 422), or the SDK refused to send it.
OvokAuthenticationErrorCredentials are missing, invalid or expired (401).
OvokPermissionErrorSigned in, but not allowed (403).
OvokNotFoundErrorThe resource does not exist (404).
OvokConflictErrorThe request conflicts with the current state (409).
OvokRateLimitErrorToo many requests (429).
OvokServiceErrorThe server failed or was unavailable (5xx).
OvokConnectionErrorNo response arrived.
OvokConfigErrorA client option is invalid, or this client cannot take the action.
import time

from ovok_sdk import OvokNotFoundError, OvokRateLimitError, OvokValidationError

try:
    patient = ovok.fhir.read("Patient", patient_id)
except OvokNotFoundError:
    patient = None
except OvokValidationError as error:
    for field in error.field_errors:
        print("/".join(field.path), field.message)
    raise
except OvokRateLimitError as error:
    time.sleep((error.retry_after_ms or 1_000) / 1_000)
    raise

Each error carries status, code, type, trace_id and request_id; quote trace_id when reporting a failure. The client already retries safe requests that fail on the network (max_network_retries, two by default).

Last updated on