Skip to content

Commit

Permalink
Better error when requesting a show by ID which doesn't exist
Browse files Browse the repository at this point in the history
Closes #54
  • Loading branch information
dbr committed Sep 25, 2017
1 parent bc654c8 commit 2505ae1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tests/test_tvdb_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ def test_shownotfound(self):
with pytest.raises(tvdb_shownotfound):
self.t['the fake show thingy']

def test_shownotfound(self):
"""Checks exception is thrown when episode doesn't exist.
"""
with pytest.raises(tvdb_shownotfound):
self.t[999999999999999]

def test_episodenotfound(self):
"""Checks exception is raised for non-existent episode
"""
Expand Down
10 changes: 8 additions & 2 deletions tvdb_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,10 +864,16 @@ def _loadUrl(self, url, data=None, recache=False, language=None):
# raise(tvdb_resourcenotfound)
# handle no data at a different level so it is more specific
pass
if error == u'Not Authorized':
elif error == u'Not Authorized':
raise(tvdb_notauthorized)
elif error.startswith(u"ID: ") and error.endswith("not found"):
# FIXME: Refactor error out of in this method
raise tvdb_shownotfound("%s" % error)
else:
raise tvdb_error("%s" % error)

if errors:
if u'invalidLanguage' in errors:
if errors and u'invalidLanguage' in errors:
# raise(tvdb_invalidlanguage(errors[u'invalidLanguage']))
# invalidLanguage does not mean there is no data
# there is just less data
Expand Down

0 comments on commit 2505ae1

Please sign in to comment.