Skip to main content

exceptions

Exceptions the FHIR R4 backend raises.

Classes​

FHIRR4APIError​

class FHIRR4APIError(*args, **kwargs):

Exception raised when interacting with FHIR R4 APIs.

An EHRRequestError, so a caller catches it without naming the backend.

FHIRR4AuthenticationError​

class FHIRR4AuthenticationError(    status_code: int, message: str, response_content: str | None = None,):

Exception for authentication/authorization errors (401).

FHIRR4CodesRejectedError​

class FHIRR4CodesRejectedError(resource_type: str, codes: Sequence[str]):

Raised when the server refused every code a search asked for.

Each code was refused as a search value (a 400 naming it), by this search or by an earlier one whose refusal still stands, so the search could not be answered for any of them. A plain FHIRR4APIError rather than an EHRFetchUnsupportedError: the resource type is still served, and other searches for it still work, so the result stays "could not determine" rather than "confirmed none".

Arguments

  • resource_type: The resource type that was searched.
  • codes: The refused code search values.

FHIRR4DataError​

class FHIRR4DataError(*args, **kwargs):

Exception raised when we have exceeded any FHIR R4 call limit.

FHIRR4ForbiddenError​

class FHIRR4ForbiddenError(    status_code: int, message: str, response_content: str | None = None,):

Exception for forbidden access (403).

FHIRR4GetPatientInfoError​

class FHIRR4GetPatientInfoError(*args, **kwargs):

Could not retrieve patient info.

FHIRR4HTTPError​

class FHIRR4HTTPError(    status_code: int, message: str, response_content: str | None = None,):

Exception for HTTP errors from FHIR R4 API.

FHIRR4MedicationsUnsupportedError​

class FHIRR4MedicationsUnsupportedError(*args, **kwargs):

No medication-related resource type is supported by this server.

A distinct subclass of FHIRR4GetPatientInfoError so a caller (or future monitoring/retry logic) can tell "this server structurally does not support any medication resource" apart from a genuine transient fetch failure — even though both currently degrade the same way in get_patient_code_states (medication_codes=None).

FHIRR4OperationOutcomeError​

class FHIRR4OperationOutcomeError(*args, **kwargs):

Exception for server side operation errors.

These can be raised even when server returns a 200, accompanied by an OperationOutcome resource that details

FHIRR4QuotaExceeded​

class FHIRR4QuotaExceeded(*args, **kwargs):

Exception raised when we have exceeded any FHIR R4 call limit.

FHIRR4RateLimitError​

class FHIRR4RateLimitError(    status_code: int, message: str, response_content: str | None = None,):

Exception for rate limiting errors (429).

FHIRR4ResourceTypeNotSupportedError​

class FHIRR4ResourceTypeNotSupportedError(resource_type: str, message: str | None = None):

Raised when the server does not support a requested resource type.

Some FHIR servers answer a request for a resource type they do not implement with a 404 (rather than an empty bundle). This is a permanent, server-wide condition — unlike a per-patient "not found" — so callers can stop re-requesting the type for the remainder of the run.

Subclasses ResourceNotFound so existing handlers that treat the type as "no data" continue to work unchanged; callers that want to short-circuit catch this more specific type first.

Also subclasses EHRFetchUnsupportedError, which is what lets it travel: the querier entry points convert every non-auth failure into a FHIRR4GetPatientInfoError so their callers only ever have to catch GetPatientInfoError, and a bare ResourceNotFound is not one. Being an EHRFetchUnsupportedError — and so a GetPatientInfoError — this can be let through those entry points unconverted, carrying "the server cannot serve this type" all the way to the consumer that has to tell a structural gap from an outage. That is the same claim FHIRServerKnowledge records; the knowledge is the short-circuit that stops the type being requested again while the finding stands, not the channel the claim travels down.

warning

That inheritance makes the default for a new handler the unsafe one: an except ResourceNotFound written without thinking about this will report a permanently-absent resource type as "this patient has none", which readers treat as a confirmed negative. Any handler that means "not found for this patient" must catch this type first and re-raise. Every current site does (SearchExecutor.search, .get and .first); the one deliberate exception is the per-resource-type medications loop, where "unavailable" really is the intended reading.

Arguments

  • resource_type: The resource type the server does not support.
  • message: Optional diagnostic detail from the server's OperationOutcome.

FHIRR4ResourceTypeUnresponsiveError​

class FHIRR4ResourceTypeUnresponsiveError(resource_type: str):

Raised when a search for a resource type keeps timing out.

After MAX_CONSECUTIVE_TIMEOUTS consecutive read timeouts for one search, ServerKnowledge gives that search up until its recheck is due, and later searches like it raise this instead of re-paying the timeout. A search that has gone quiet would otherwise cost every patient in the cohort a full round of transport retries.

Deliberately an EHRFetchUnavailableError, and pointedly not a FHIRR4ResourceTypeNotSupportedError: a timeout is no evidence about what the server implements. The distinction decides how the blank is stored — the unsupported branch settles as FetchState.UNSUPPORTED, which the freshness gate reads as a reason never to ask again, while this stays FetchState.UNAVAILABLE and is re-tested on the next run.

Arguments

  • resource_type: The resource type whose searches stopped answering.

FHIRR4ServerError​

class FHIRR4ServerError(    status_code: int, message: str, response_content: str | None = None,):

Exception for server errors (5xx).

FHIRR4TokenUnavailableError​

class FHIRR4TokenUnavailableError(message: str):

The client's token provider could not supply a token to send.

Raised before the request is sent, in place of it. It is a FHIRR4AuthenticationError, so every FHIR R4 handler that lets an authentication error through also lets this through. The client counts it against the auth budget, and the patient's lookup fails as a whole and is recorded as AUTH_REJECTED, not as a generic fetch failure. It is also an EHRTokenUnavailableError, the backend-neutral name for the same failure.

status_code is 401, because no response was received. The message has no HTTP prefix, for the same reason.

Arguments

  • message: Why no token could be obtained.

NoFHIRR4PatientIDError​

class NoFHIRR4PatientIDError(*args, **kwargs):

Exception raised when patient ID could not be extracted.

NoMatchingFHIRR4PatientError​

class NoMatchingFHIRR4PatientError(*args, **kwargs):

Exception raised when no patient matching filters is found.

NonSpecificFHIRR4PatientError​

class NonSpecificFHIRR4PatientError(*args, **kwargs):

Exception raised when patient could not be narrowed to a single person.