(func)
| 4 | |
| 5 | |
| 6 | def log_http_errors(func): |
| 7 | @wraps(func) |
| 8 | async def wrapper(*args, **kwargs): |
| 9 | try: |
| 10 | return await func(*args, **kwargs) |
| 11 | except httpx.HTTPStatusError as e: |
| 12 | # raise a new exception with the status code, url, and "detail" key if it exists |
| 13 | try: |
| 14 | detail = e.response.json().get("detail", None) |
| 15 | except Exception: |
| 16 | # if we can't parse the response as json, just raise the original exception |
| 17 | raise e |
| 18 | raise Exception( |
| 19 | f"[HTTP {e.response.status_code}] {e.request.url} {detail}" |
| 20 | ) from e |
| 21 | |
| 22 | return wrapper |
nothing calls this directly
no outgoing calls
no test coverage detected