diff --git a/fbchat/_exception.py b/fbchat/_exception.py index b84c5b9..64632cb 100644 --- a/fbchat/_exception.py +++ b/fbchat/_exception.py @@ -1,32 +1,32 @@ +import attr + +# Not frozen, since that doesn't work in PyPy +attrs_exception = attr.s(slots=True, auto_exc=True) + + +@attrs_exception class FBchatException(Exception): """Custom exception thrown by ``fbchat``. All exceptions in the ``fbchat`` module inherits this. """ + message = attr.ib() + +@attrs_exception class FBchatFacebookError(FBchatException): + """Raised when Facebook returns an error.""" + #: The error code that Facebook returned - fb_error_code = None + fb_error_code = attr.ib(None) #: The error message that Facebook returned (In the user's own language) - fb_error_message = None + fb_error_message = attr.ib(None) #: The status code that was sent in the HTTP response (e.g. 404) (Usually only set if not successful, aka. not 200) - request_status_code = None - - def __init__( - self, - message, - fb_error_code=None, - fb_error_message=None, - request_status_code=None, - ): - super(FBchatFacebookError, self).__init__(message) - """Thrown by ``fbchat`` when Facebook returns an error""" - self.fb_error_code = str(fb_error_code) - self.fb_error_message = fb_error_message - self.request_status_code = request_status_code + request_status_code = attr.ib(None) +@attrs_exception class FBchatInvalidParameters(FBchatFacebookError): """Raised by Facebook if: @@ -36,17 +36,19 @@ class FBchatInvalidParameters(FBchatFacebookError): """ +@attrs_exception class FBchatNotLoggedIn(FBchatFacebookError): """Raised by Facebook if the client has been logged out.""" - fb_error_code = "1357001" + fb_error_code = attr.ib("1357001") +@attrs_exception class FBchatPleaseRefresh(FBchatFacebookError): """Raised by Facebook if the client has been inactive for too long. This error usually happens after 1-2 days of inactivity. """ - fb_error_code = "1357004" - fb_error_message = "Please try closing and re-opening your browser window." + fb_error_code = attr.ib("1357004") + fb_error_message = attr.ib("Please try closing and re-opening your browser window.") diff --git a/pyproject.toml b/pyproject.toml index 8613c70..fa008f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ maintainer-email = "madsmtm@gmail.com" home-page = "https://github.com/carpedm20/fbchat/" requires = [ "aenum~=2.0", - "attrs>=18.2", + "attrs>=19.1", "requests~=2.19", "beautifulsoup4~=4.0", ]