Skip to content

service_result

service_result

Service result wrapper for operation outcomes.

Classes

ServiceResult

Bases: BaseModel, Generic[T]

A uniform result object for all service runners. - success=False means a breaking error: data will be None - success=True but non-empty errors means warnings only - data can be any type

Functions
ok classmethod
ok(data, errors=None)

Use when your runner fetched data; pass warnings in errors if any.

Source code in src/pyetm/services/service_result.py
@classmethod
def ok(cls, data: T, errors: Optional[list[str]] = None) -> ServiceResult[T]:
    """Use when your runner fetched data; pass warnings in `errors` if any."""
    # copy warnings list to avoid external mutations
    err_copy: list[str] = list(errors) if errors else []
    return cls(success=True, data=data, errors=err_copy)
fail classmethod
fail(errors)

Use when a critical error happened and you cannot proceed.

Source code in src/pyetm/services/service_result.py
@classmethod
def fail(cls, errors: list[str]) -> ServiceResult[Any]:
    """Use when a critical error happened and you cannot proceed."""
    err_copy: list[str] = list(errors)
    return cls(success=False, data=None, errors=err_copy)