44 lines
925 B
Python
44 lines
925 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
|
||
|
|
class ZaloUserError(Exception):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class ZaloUserAuthError(ZaloUserError):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class ZaloUserConnectionError(ZaloUserError):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class ZaloUserSendError(ZaloUserError):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class ZaloUserQRExpiredError(ZaloUserAuthError):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class ZaloUserQRDeclinedError(ZaloUserAuthError):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class ZaloUserNotAuthenticatedError(ZaloUserAuthError):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
class ZaloUserWatchdogTimeoutError(ZaloUserConnectionError):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
def classify_http_error(status_code: int, body: str = "") -> ZaloUserError:
|
||
|
|
if status_code == 401:
|
||
|
|
return ZaloUserAuthError(f"Authentication failed: {body}")
|
||
|
|
if status_code == 403:
|
||
|
|
return ZaloUserAuthError(f"Access denied: {body}")
|
||
|
|
if 500 <= status_code < 600:
|
||
|
|
return ZaloUserConnectionError(f"Sidecar error ({status_code}): {body}")
|
||
|
|
return ZaloUserError(f"HTTP {status_code}: {body}")
|