(logger: logging.Logger | None = None)
| 6 | |
| 7 | |
| 8 | def 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 |
nothing calls this directly
no outgoing calls
no test coverage detected