Skip to content

Commit

Permalink
NEW: add BackendError.inner property ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenein committed May 27, 2024
1 parent e650f52 commit 112aa42
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions combadge/core/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,33 @@ class BackendError(CombadgeError, metaclass=_BackendErrorMeta):
Base error for any backend errors.
Examples:
Handling inner error:
>>> try:
>>> client.method()
>>> except BackendError as e:
>>> match e.inner:
>>> case httpx.TimeoutException():
>>> # Handle timeout error.
>>> case _:
>>> raise
Wrapping client call (only needed for a new backend implementation):
>>> with BackendError:
>>> ...
"""

def __init__(self, inner: BaseException) -> None:
"""
Instantiate the backend error.
Args:
inner: wrapped backend client exception
"""
super().__init__(inner)

@property
def inner(self) -> BaseException:
"""Get the wrapped backend client exception."""
return self.args[0]
2 changes: 1 addition & 1 deletion combadge/support/zeep/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _get_operation(self, name: str) -> _OperationProxyT:
try:
return self._service[name]
except AttributeError as e:
raise InvalidOperationError(f"available operations are: {dir(self._service)}") from e
raise InvalidOperationError(e) from e

@staticmethod
def _parse_soap_fault(exception: Fault, fault_type: TypeAdapter[_SoapFaultT]) -> _SoapFaultT:
Expand Down

0 comments on commit 112aa42

Please sign in to comment.