Remove FBchatUserError in favor of builtin exceptions

This commit is contained in:
Mads Marquart
2019-08-30 18:06:05 +02:00
parent 91cf4589a5
commit b5a37e35c6
7 changed files with 17 additions and 22 deletions

View File

@@ -21,8 +21,8 @@ Traceback (most recent call last):
File "[site-packages]/fbchat/client.py", line 78, in __init__
self.login(email, password, max_tries)
File "[site-packages]/fbchat/client.py", line 407, in login
raise FBchatUserError('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)
raise FBchatException('Login failed. Check email/password. (Failed on URL: {})'.format(login_url))
fbchat.FBchatException: Login failed. Check email/password. (Failed on URL: https://m.facebook.com/login.php?login_attempt=1)
```
## Environment information

View File

@@ -38,7 +38,6 @@ Exceptions
.. autoexception:: FBchatException()
.. autoexception:: FBchatFacebookError()
.. autoexception:: FBchatUserError()
Attachments
-----------

View File

@@ -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!
from . import _core, _util
from ._exception import FBchatException, FBchatFacebookError, FBchatUserError
from ._exception import FBchatException, FBchatFacebookError
from ._thread import ThreadType, ThreadLocation, ThreadColor, Thread
from ._user import TypingStatus, User, ActiveStatus
from ._group import Group

View File

@@ -7,7 +7,7 @@ from collections import OrderedDict
from ._core import log
from . import _util, _graphql, _state
from ._exception import FBchatException, FBchatFacebookError, FBchatUserError
from ._exception import FBchatException, FBchatFacebookError
from ._thread import ThreadType, ThreadLocation, ThreadColor
from ._user import TypingStatus, User, ActiveStatus
from ._group import Group
@@ -176,10 +176,10 @@ class Client:
self.onLoggingIn(email=email)
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):
raise FBchatUserError("Email and password not set")
raise ValueError("Email and password not set")
for i in range(1, max_tries + 1):
try:
@@ -560,7 +560,7 @@ class Client:
if thread.type == ThreadType.USER:
users[id_] = thread
else:
raise FBchatUserError("Thread {} was not a user".format(thread))
raise ValueError("Thread {} was not a user".format(thread))
return users
@@ -585,7 +585,7 @@ class Client:
if thread.type == ThreadType.PAGE:
pages[id_] = thread
else:
raise FBchatUserError("Thread {} was not a page".format(thread))
raise ValueError("Thread {} was not a page".format(thread))
return pages
@@ -607,7 +607,7 @@ class Client:
if thread.type == ThreadType.GROUP:
groups[id_] = thread
else:
raise FBchatUserError("Thread {} was not a group".format(thread))
raise ValueError("Thread {} was not a group".format(thread))
return groups
@@ -739,12 +739,12 @@ class Client:
FBchatException: If request failed
"""
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:
loc_str = thread_location.value
else:
raise FBchatUserError('"thread_location" must be a value of ThreadLocation')
raise TypeError('"thread_location" must be a value of ThreadLocation')
params = {
"limit": limit,
@@ -1033,7 +1033,7 @@ class Client:
)
elif isinstance(quick_reply, QuickReplyLocation):
if not isinstance(payload, LocationAttachment):
raise ValueError(
raise TypeError(
"Payload must be an instance of `fbchat.LocationAttachment`"
)
return self.sendLocation(
@@ -1274,7 +1274,7 @@ class Client:
data = self._oldMessage(message)._to_send_data()
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]):
data["specific_to_list[{}]".format(i)] = "fbid:{}".format(user_id)
@@ -1305,7 +1305,7 @@ class Client:
for i, user_id in enumerate(user_ids):
if user_id == self._uid:
raise FBchatUserError(
raise ValueError(
"Error when adding users: Cannot add self to group thread"
)
else:

View File

@@ -50,7 +50,3 @@ class FBchatPleaseRefresh(FBchatFacebookError):
fb_error_code = "1357004"
fb_error_message = "Please try closing and re-opening your browser window."
class FBchatUserError(FBchatException):
"""Thrown by ``fbchat`` when wrong values are entered."""

View File

@@ -147,7 +147,7 @@ class State:
if is_home(r.url):
return cls.from_session(session=session)
else:
raise _exception.FBchatUserError(
raise _exception.FBchatException(
"Login failed. Check email/password. "
"(Failed on url: {})".format(r.url)
)

View File

@@ -3,7 +3,7 @@ import py_compile
from glob import glob
from os import path, environ
from fbchat import FBchatUserError, Message, Client
from fbchat import FBchatException, Message, Client
@pytest.mark.offline
@@ -24,7 +24,7 @@ def test_login(client1):
assert not client1.isLoggedIn()
with pytest.raises(FBchatUserError):
with pytest.raises(FBchatException):
client1.login("<invalid email>", "<invalid password>", max_tries=1)
client1.login(email, password)