MCPcopy Create free account
hub / github.com/LaunchPlatform/beanhub-cli / handle_api_exception

Function handle_api_exception

beanhub_cli/api_helpers.py:8–33  ·  view source on GitHub ↗
(logger: logging.Logger | None = None)

Source from the content-addressed store, hash-verified

6
7
8def handle_api_exception(logger: logging.Logger | None = None):
9 def decorator(func: typing.Callable):
10 @functools.wraps(func)
11 def callee(*args, **kwargs):
12 from .internal_api.errors import UnexpectedStatus
13 from .internal_api.models import GenericError
14
15 try:
16 return func(*args, **kwargs)
17 except UnexpectedStatus as exp:
18 log = logger or logging.getLogger(__name__)
19 error = None
20 try:
21 error = GenericError.from_dict(json.loads(exp.content))
22 except ValueError:
23 pass
24 log.error(
25 "Failed to make BeanHub API call with code %s and error: %s",
26 exp.status_code,
27 error.detail if error is not None else exp.content,
28 )
29 sys.exit(-1)
30
31 return callee
32
33 return decorator

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected