diff --git a/fbchat/_exception.py b/fbchat/_exception.py index 76aa047..b35466b 100644 --- a/fbchat/_exception.py +++ b/fbchat/_exception.py @@ -46,6 +46,11 @@ class ParseError(FacebookError): return msg.format(self.message, self.data) +@attr.s(slots=True, auto_exc=True) +class NotLoggedIn(FacebookError): + """Raised by Facebook if the client has been logged out.""" + + @attr.s(slots=True, auto_exc=True) class ExternalError(FacebookError): """Base class for errors that Facebook return.""" @@ -86,13 +91,6 @@ class InvalidParameters(ExternalError): """ -@attr.s(slots=True, auto_exc=True) -class NotLoggedIn(ExternalError): - """Raised by Facebook if the client has been logged out.""" - - code = attr.ib() - - @attr.s(slots=True, auto_exc=True) class PleaseRefresh(ExternalError): """Raised by Facebook if the client has been inactive for too long. @@ -108,7 +106,7 @@ def handle_payload_error(j): return code = j["error"] if code == 1357001: - error_cls = NotLoggedIn + raise NotLoggedIn(j["errorSummary"]) elif code == 1357004: error_cls = PleaseRefresh elif code in (1357031, 1545010, 1545003): diff --git a/fbchat/_session.py b/fbchat/_session.py index 6e34d67..2bedefc 100644 --- a/fbchat/_session.py +++ b/fbchat/_session.py @@ -308,7 +308,7 @@ class Session: # Fall back to searching with a regex res = FB_DTSG_REGEX.search(r.text) if not res: - raise ValueError("Failed loading session, could not find fb_dtsg") + raise _exception.NotLoggedIn("Could not find fb_dtsg") fb_dtsg = res.group(1) revision = int(r.text.split('"client_revision":', 1)[1].split(",", 1)[0])