Skip to content

Commit 84fca22

Browse files
committed
Refactor Exceptions
1 parent 547fca0 commit 84fca22

27 files changed

Lines changed: 121 additions & 112 deletions

docs/user/api.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ Exceptions
126126
:show-inheritance:
127127
:members:
128128

129-
.. autoexception:: SparkApiError()
129+
.. autoexception:: ApiError()
130130
:show-inheritance:
131131
:members:
132132

133-
.. autoexception:: SparkRateLimitError()
133+
.. autoexception:: RateLimitError()
134134
:show-inheritance:
135135
:members:
136136

docs/user/intro.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ With webexteamsdk, the above Python code can be consolidated to the following:
6161
message = api.messages.create('<room_id>', text='<message_text>')
6262
print("New message created, with ID:", message.id)
6363
print(message.text)
64-
except SparkApiError as e:
64+
except ApiError as e:
6565
print(e)
6666
6767

docs/user/quickstart.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ Catching Exceptions
262262
-------------------
263263

264264
If something should go wrong with the API call, an exception will be raised.
265-
:exc:`SparkApiError` exceptions are raised when an error condition is
265+
:exc:`ApiError` exceptions are raised when an error condition is
266266
returned from the Webex Teams cloud. Details will be provided in the error
267267
message.
268268

269269
.. code-block:: python
270270
271-
>>> from webexteamsdk import CiscoSparkAPI, SparkApiError
271+
>>> from webexteamsdk import CiscoSparkAPI, ApiError
272272
>>> api = CiscoSparkAPI()
273273
>>> room = api.rooms.create("webexteamsdk Test Room")
274274
>>> me = api.people.me()
@@ -281,19 +281,19 @@ message.
281281
check_response_code(response, erc)
282282
File "webexteamsdk/utils.py", line 104, in check_response_code
283283
response=response)
284-
webexteamsdk.exceptions.SparkApiError: Response Code [409] - The request
284+
webexteamsdk.exceptions.ApiError: Response Code [409] - The request
285285
could not be processed because it conflicts with some established rule of
286286
the system. For example, a person may not be added to a room more than
287287
once.
288288
289289
You can catch any errors returned by the Webex Teams cloud by catching
290-
:exc:`SparkApiError` exceptions in a try-except block.
290+
:exc:`ApiError` exceptions in a try-except block.
291291

292292
.. code-block:: python
293293
294294
>>> try:
295295
... api.memberships.create(roomId=room.id, personId=me.id)
296-
... except SparkApiError as e:
296+
... except ApiError as e:
297297
... memberships = api.memberships.list(roomId=room.id)
298298
... for membership in memberships:
299299
... if membership.personId == me.id:

tests/api/test_memberships.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def are_valid_memberships(iterable):
8383
def membership_exists(api, membership):
8484
try:
8585
get_membership_by_id(api, membership.id)
86-
except webexteamsdk.SparkApiError:
86+
except webexteamsdk.ApiError:
8787
return False
8888
else:
8989
return True

tests/api/test_messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def are_valid_messages(iterable):
5151
def message_exists(api, message):
5252
try:
5353
api.messages.get(message.id)
54-
except webexteamsdk.SparkApiError:
54+
except webexteamsdk.ApiError:
5555
return False
5656
else:
5757
return True
@@ -95,7 +95,7 @@ def inner_function(roomId, **message_attributes):
9595
for message in messages:
9696
try:
9797
delete_message(api, message)
98-
except webexteamsdk.SparkApiError as e:
98+
except webexteamsdk.ApiError as e:
9999
pass
100100

101101

tests/api/test_people.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def are_valid_people(iterable):
6666
def person_exists(api, person):
6767
try:
6868
get_person_by_id(api, person.id)
69-
except webexteamsdk.SparkApiError:
69+
except webexteamsdk.ApiError:
7070
return False
7171
else:
7272
return True

tests/api/test_rooms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def create_team_room(api, team, room_title):
2929
def delete_room(api, room):
3030
try:
3131
api.rooms.delete(room.id)
32-
except webexteamsdk.SparkApiError as e:
32+
except webexteamsdk.ApiError as e:
3333
if e.response.status_code == 404:
3434
# Room doesn't exist
3535
pass
@@ -48,7 +48,7 @@ def are_valid_rooms(iterable):
4848
def room_exists(api, room):
4949
try:
5050
api.rooms.get(room.id)
51-
except webexteamsdk.SparkApiError:
51+
except webexteamsdk.ApiError:
5252
return False
5353
else:
5454
return True

tests/api/test_teammemberships.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def are_valid_team_memberships(iterable):
6464
def membership_exists(api, membership):
6565
try:
6666
get_team_membership_by_id(api, membership.id)
67-
except webexteamsdk.SparkApiError:
67+
except webexteamsdk.ApiError:
6868
return False
6969
else:
7070
return True

tests/api/test_teams.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def get_team_details_by_id(api, team_id):
3030
def delete_team(api, team):
3131
try:
3232
api.teams.delete(team.id)
33-
except webexteamsdk.SparkApiError as e:
33+
except webexteamsdk.ApiError as e:
3434
if e.response.status_code == 404:
3535
# Team doesn't exist
3636
pass
@@ -49,7 +49,7 @@ def are_valid_teams(iterable):
4949
def team_exists(api, team):
5050
try:
5151
get_team_details_by_id(api, team.id)
52-
except webexteamsdk.SparkApiError:
52+
except webexteamsdk.ApiError:
5353
return False
5454
else:
5555
return True

tests/test_restsession.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
def rate_limit_detected(w):
2424
"""Check to see if a rate-limit warning is in the warnings list."""
2525
while w:
26-
if issubclass(w.pop().category, webexteamsdk.SparkRateLimitWarning):
26+
if issubclass(w.pop().category, webexteamsdk.RateLimitWarning):
2727
return True
2828
break
2929
return False

0 commit comments

Comments
 (0)