ForcePilot/backend/package/yuxi/channel/extensions/bluebubbles/errors.py

53 lines
989 B
Python
Raw Normal View History

class BlueBubblesError(Exception):
pass
class AuthenticationError(BlueBubblesError):
pass
class NotFoundError(BlueBubblesError):
pass
class ConflictError(BlueBubblesError):
pass
class ServerError(BlueBubblesError):
pass
class NetworkTimeoutError(BlueBubblesError):
pass
class ConnectionRefusedError(BlueBubblesError):
pass
class PrivateApiUnavailableError(BlueBubblesError):
pass
class EmptyMessageError(BlueBubblesError):
pass
class MediaSecurityError(BlueBubblesError):
pass
HTTP_STATUS_TO_ERROR: dict[int, type[BlueBubblesError]] = {
401: AuthenticationError,
404: NotFoundError,
409: ConflictError,
}
def classify_response_error(status_code: int, message: str = "") -> BlueBubblesError:
if status_code >= 500:
return ServerError(message or f"Server error: {status_code}")
error_cls = HTTP_STATUS_TO_ERROR.get(status_code, BlueBubblesError)
return error_cls(message or f"HTTP {status_code}")