Error Handling¶
- hl7types.utils.error.err_from_pydantic_error(error, version)¶
Convert a single Pydantic error dict into a version-appropriate
ERRsegment.- Parameters:
error (dict) – A single error entry from
ValidationError.errors().version (str) – The HL7 version string, e.g.
"2.5.1"or"2.8.2". Determines the structure of the returnedERRsegment.
- Returns:
An
ERRsegment instance for the given version.- Return type:
- Raises:
ValueError – If no
ERRsegment class is found for the given version.
- hl7types.utils.error.errs_from_exception(exc, version)¶
Convert an exception into a list of version-appropriate
ERRsegments.Only
pydantic.ValidationErroris handled. Any other exception type returns an empty list.- Parameters:
exc (Exception) – The exception to convert. Typically a
pydantic.ValidationErrorraised bydecode_er7or direct model construction.version (str) – The HL7 version string, e.g.
"2.5.1"or"2.8.2". Determines the structure of each returnedERRsegment.
- Returns:
One
ERRsegment per violated field, or an empty list ifexcis not aValidationError.- Return type:
list[HL7Model]