Skip to content

Commit c8a4e29

Browse files
Rob PercivalRJPercival
authored andcommitted
Store HTTP status code in HTTP{Client,Server}Error
Allows code handling these errors to distinguish between different kinds of errors.
1 parent b61c0fa commit c8a4e29

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

python/ct/client/log_client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,16 @@ class HTTPError(Error):
3434

3535
class HTTPClientError(HTTPError):
3636
"""HTTP 4xx."""
37-
pass
37+
def __init__(self, code, reason, content, headers):
38+
super(HTTPError, self).__init__("%s (%s) %s" % (reason, content, headers))
39+
self.code = code
3840

3941

4042
class HTTPServerError(HTTPError):
4143
"""HTTP 5xx."""
42-
pass
44+
def __init__(self, code, reason, content, headers):
45+
super(HTTPError, self).__init__("%s (%s) %s" % (reason, content, headers))
46+
self.code = code
4347

4448

4549
class InvalidRequestError(Error):
@@ -197,9 +201,9 @@ def check_response_status(code, reason, content='', headers=''):
197201
if code == 200:
198202
return
199203
elif 400 <= code < 500:
200-
raise HTTPClientError("%s (%s) %s" % (reason, content, headers))
204+
raise HTTPClientError(code, reason, content, headers)
201205
elif 500 <= code < 600:
202-
raise HTTPServerError("%s (%s) %s" % (reason, content, headers))
206+
raise HTTPServerError(code, reason, content, headers)
203207
else:
204208
raise HTTPError("%s (%s) %s" % (reason, content, headers))
205209

0 commit comments

Comments
 (0)