Remove FBchatUserError in favor of builtin exceptions
This commit is contained in:
4
.github/ISSUE_TEMPLATE/bug_report.md
vendored
4
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -21,8 +21,8 @@ Traceback (most recent call last):
|
|||||||
File "[site-packages]/fbchat/client.py", line 78, in __init__
|
File "[site-packages]/fbchat/client.py", line 78, in __init__
|
||||||
self.login(email, password, max_tries)
|
self.login(email, password, max_tries)
|
||||||
File "[site-packages]/fbchat/client.py", line 407, in login
|
File "[site-packages]/fbchat/client.py", line 407, in login
|
||||||
raise FBchatUserError('Login failed. Check email/password. (Failed on URL: {})'.format(login_url))
|
raise FBchatException('Login failed. Check email/password. (Failed on URL: {})'.format(login_url))
|
||||||
fbchat.models.FBchatUserError: Login failed. Check email/password. (Failed on URL: https://m.facebook.com/login.php?login_attempt=1)
|
fbchat.FBchatException: Login failed. Check email/password. (Failed on URL: https://m.facebook.com/login.php?login_attempt=1)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Environment information
|
## Environment information
|
||||||
|
@@ -38,7 +38,6 @@ Exceptions
|
|||||||
|
|
||||||
.. autoexception:: FBchatException()
|
.. autoexception:: FBchatException()
|
||||||
.. autoexception:: FBchatFacebookError()
|
.. autoexception:: FBchatFacebookError()
|
||||||
.. autoexception:: FBchatUserError()
|
|
||||||
|
|
||||||
Attachments
|
Attachments
|
||||||
-----------
|
-----------
|
||||||
|
@@ -11,7 +11,7 @@ _logging.getLogger(__name__).addHandler(_logging.NullHandler())
|
|||||||
|
|
||||||
# The order of these is somewhat significant, e.g. User has to be imported after Thread!
|
# The order of these is somewhat significant, e.g. User has to be imported after Thread!
|
||||||
from . import _core, _util
|
from . import _core, _util
|
||||||
from ._exception import FBchatException, FBchatFacebookError, FBchatUserError
|
from ._exception import FBchatException, FBchatFacebookError
|
||||||
from ._thread import ThreadType, ThreadLocation, ThreadColor, Thread
|
from ._thread import ThreadType, ThreadLocation, ThreadColor, Thread
|
||||||
from ._user import TypingStatus, User, ActiveStatus
|
from ._user import TypingStatus, User, ActiveStatus
|
||||||
from ._group import Group
|
from ._group import Group
|
||||||
|
@@ -7,7 +7,7 @@ from collections import OrderedDict
|
|||||||
from ._core import log
|
from ._core import log
|
||||||
from . import _util, _graphql, _state
|
from . import _util, _graphql, _state
|
||||||
|
|
||||||
from ._exception import FBchatException, FBchatFacebookError, FBchatUserError
|
from ._exception import FBchatException, FBchatFacebookError
|
||||||
from ._thread import ThreadType, ThreadLocation, ThreadColor
|
from ._thread import ThreadType, ThreadLocation, ThreadColor
|
||||||
from ._user import TypingStatus, User, ActiveStatus
|
from ._user import TypingStatus, User, ActiveStatus
|
||||||
from ._group import Group
|
from ._group import Group
|
||||||
@@ -176,10 +176,10 @@ class Client:
|
|||||||
self.onLoggingIn(email=email)
|
self.onLoggingIn(email=email)
|
||||||
|
|
||||||
if max_tries < 1:
|
if max_tries < 1:
|
||||||
raise FBchatUserError("Cannot login: max_tries should be at least one")
|
raise ValueError("Cannot login: max_tries should be at least one")
|
||||||
|
|
||||||
if not (email and password):
|
if not (email and password):
|
||||||
raise FBchatUserError("Email and password not set")
|
raise ValueError("Email and password not set")
|
||||||
|
|
||||||
for i in range(1, max_tries + 1):
|
for i in range(1, max_tries + 1):
|
||||||
try:
|
try:
|
||||||
@@ -560,7 +560,7 @@ class Client:
|
|||||||
if thread.type == ThreadType.USER:
|
if thread.type == ThreadType.USER:
|
||||||
users[id_] = thread
|
users[id_] = thread
|
||||||
else:
|
else:
|
||||||
raise FBchatUserError("Thread {} was not a user".format(thread))
|
raise ValueError("Thread {} was not a user".format(thread))
|
||||||
|
|
||||||
return users
|
return users
|
||||||
|
|
||||||
@@ -585,7 +585,7 @@ class Client:
|
|||||||
if thread.type == ThreadType.PAGE:
|
if thread.type == ThreadType.PAGE:
|
||||||
pages[id_] = thread
|
pages[id_] = thread
|
||||||
else:
|
else:
|
||||||
raise FBchatUserError("Thread {} was not a page".format(thread))
|
raise ValueError("Thread {} was not a page".format(thread))
|
||||||
|
|
||||||
return pages
|
return pages
|
||||||
|
|
||||||
@@ -607,7 +607,7 @@ class Client:
|
|||||||
if thread.type == ThreadType.GROUP:
|
if thread.type == ThreadType.GROUP:
|
||||||
groups[id_] = thread
|
groups[id_] = thread
|
||||||
else:
|
else:
|
||||||
raise FBchatUserError("Thread {} was not a group".format(thread))
|
raise ValueError("Thread {} was not a group".format(thread))
|
||||||
|
|
||||||
return groups
|
return groups
|
||||||
|
|
||||||
@@ -739,12 +739,12 @@ class Client:
|
|||||||
FBchatException: If request failed
|
FBchatException: If request failed
|
||||||
"""
|
"""
|
||||||
if limit > 20 or limit < 1:
|
if limit > 20 or limit < 1:
|
||||||
raise FBchatUserError("`limit` should be between 1 and 20")
|
raise ValueError("`limit` should be between 1 and 20")
|
||||||
|
|
||||||
if thread_location in ThreadLocation:
|
if thread_location in ThreadLocation:
|
||||||
loc_str = thread_location.value
|
loc_str = thread_location.value
|
||||||
else:
|
else:
|
||||||
raise FBchatUserError('"thread_location" must be a value of ThreadLocation')
|
raise TypeError('"thread_location" must be a value of ThreadLocation')
|
||||||
|
|
||||||
params = {
|
params = {
|
||||||
"limit": limit,
|
"limit": limit,
|
||||||
@@ -1033,7 +1033,7 @@ class Client:
|
|||||||
)
|
)
|
||||||
elif isinstance(quick_reply, QuickReplyLocation):
|
elif isinstance(quick_reply, QuickReplyLocation):
|
||||||
if not isinstance(payload, LocationAttachment):
|
if not isinstance(payload, LocationAttachment):
|
||||||
raise ValueError(
|
raise TypeError(
|
||||||
"Payload must be an instance of `fbchat.LocationAttachment`"
|
"Payload must be an instance of `fbchat.LocationAttachment`"
|
||||||
)
|
)
|
||||||
return self.sendLocation(
|
return self.sendLocation(
|
||||||
@@ -1274,7 +1274,7 @@ class Client:
|
|||||||
data = self._oldMessage(message)._to_send_data()
|
data = self._oldMessage(message)._to_send_data()
|
||||||
|
|
||||||
if len(user_ids) < 2:
|
if len(user_ids) < 2:
|
||||||
raise FBchatUserError("Error when creating group: Not enough participants")
|
raise ValueError("Error when creating group: Not enough participants")
|
||||||
|
|
||||||
for i, user_id in enumerate(user_ids + [self._uid]):
|
for i, user_id in enumerate(user_ids + [self._uid]):
|
||||||
data["specific_to_list[{}]".format(i)] = "fbid:{}".format(user_id)
|
data["specific_to_list[{}]".format(i)] = "fbid:{}".format(user_id)
|
||||||
@@ -1305,7 +1305,7 @@ class Client:
|
|||||||
|
|
||||||
for i, user_id in enumerate(user_ids):
|
for i, user_id in enumerate(user_ids):
|
||||||
if user_id == self._uid:
|
if user_id == self._uid:
|
||||||
raise FBchatUserError(
|
raise ValueError(
|
||||||
"Error when adding users: Cannot add self to group thread"
|
"Error when adding users: Cannot add self to group thread"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
@@ -50,7 +50,3 @@ class FBchatPleaseRefresh(FBchatFacebookError):
|
|||||||
|
|
||||||
fb_error_code = "1357004"
|
fb_error_code = "1357004"
|
||||||
fb_error_message = "Please try closing and re-opening your browser window."
|
fb_error_message = "Please try closing and re-opening your browser window."
|
||||||
|
|
||||||
|
|
||||||
class FBchatUserError(FBchatException):
|
|
||||||
"""Thrown by ``fbchat`` when wrong values are entered."""
|
|
||||||
|
@@ -147,7 +147,7 @@ class State:
|
|||||||
if is_home(r.url):
|
if is_home(r.url):
|
||||||
return cls.from_session(session=session)
|
return cls.from_session(session=session)
|
||||||
else:
|
else:
|
||||||
raise _exception.FBchatUserError(
|
raise _exception.FBchatException(
|
||||||
"Login failed. Check email/password. "
|
"Login failed. Check email/password. "
|
||||||
"(Failed on url: {})".format(r.url)
|
"(Failed on url: {})".format(r.url)
|
||||||
)
|
)
|
||||||
|
@@ -3,7 +3,7 @@ import py_compile
|
|||||||
|
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from os import path, environ
|
from os import path, environ
|
||||||
from fbchat import FBchatUserError, Message, Client
|
from fbchat import FBchatException, Message, Client
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.offline
|
@pytest.mark.offline
|
||||||
@@ -24,7 +24,7 @@ def test_login(client1):
|
|||||||
|
|
||||||
assert not client1.isLoggedIn()
|
assert not client1.isLoggedIn()
|
||||||
|
|
||||||
with pytest.raises(FBchatUserError):
|
with pytest.raises(FBchatException):
|
||||||
client1.login("<invalid email>", "<invalid password>", max_tries=1)
|
client1.login("<invalid email>", "<invalid password>", max_tries=1)
|
||||||
|
|
||||||
client1.login(email, password)
|
client1.login(email, password)
|
||||||
|
Reference in New Issue
Block a user