Skip to content

Commit 7990bbb

Browse files
committed
Custom exception class. Updated exception handling
1 parent 0a6f2d2 commit 7990bbb

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

Diff for: pyzootool/error.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Custom exception classes for pyzootool
3+
"""
4+
5+
class ZooError(Exception):
6+
7+
def __init__(self, reason):
8+
self.reason = reason
9+
10+
def __unicode__(self):
11+
return u'%s' % self.reason
12+
13+
def __str__(self):
14+
return self.__unicode__()
15+

Diff for: pyzootool/items.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def parse_results(self, json_data):
3232
self.tinyurl = json_data['tinyurl']
3333
self.thumbnail = json_data['thumbnail']
3434
except AttributeError:
35-
return None
35+
raise error.ZooError("Failed to parse item json")
3636

3737
class ZooItem():
3838

Diff for: pyzootool/users.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import urllib
33

44
from pyzootool import ROOT_URL
5+
from pyzootool import error
56

67
class ZooUserResult():
78

@@ -27,7 +28,7 @@ def parse_results(self, json_data):
2728
self.avatar = json_data['avatar']
2829
self.profile = json_data['profile']
2930
except AttributeError:
30-
return None
31+
raise error.ZooError("Failed to parse user json")
3132

3233
class ZooUser():
3334

0 commit comments

Comments
 (0)