Skip to content

Commit af977b6

Browse files
committed
Adding error handling if the service is unavailable
Example: except zencoder.ZencoderResponseError as e: print "Error: {1} ({0})".format(e.http_response.status, httplib.responses[e.http_response.status]) print e.content
1 parent 013ee83 commit af977b6

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

zencoder/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from core import Zencoder
2+
from core import ZencoderResponseError
23

zencoder/core.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
class ZencoderError(Exception):
2626
pass
2727

28+
class ZencoderResponseError(Exception):
29+
def __init__(self, http_response, content):
30+
self.http_response = http_response
31+
self.content = content
32+
2833
class HTTPBackend(object):
2934
"""
3035
Abstracts out an HTTP backend, but defaults to httplib2
@@ -117,10 +122,16 @@ def process(self, http_response, content):
117122
"""
118123
Returns HTTP backend agnostic Response data
119124
"""
120-
code = http_response.status
121-
body = self.decode(content)
122-
response = Response(code, body, content, http_response)
123-
return response
125+
126+
try:
127+
code = http_response.status
128+
body = self.decode(content)
129+
response = Response(code, body, content, http_response)
130+
131+
return response
132+
133+
except ValueError as e:
134+
raise ZencoderResponseError(http_response, content)
124135

125136
class Zencoder(object):
126137
""" This is the entry point to the Zencoder API """

0 commit comments

Comments
 (0)