Permalink
Browse files

Surface HTTP status codes in EchoNestAPIError; bump version to 8.0.1

  • Loading branch information...
1 parent cb952f1 commit 77a88af5e362a208c1d91159f930d5e8585cdae5 @andreasjansson andreasjansson committed Jul 22, 2013
Showing with 21 additions and 6 deletions.
  1. +4 −0 CHANGELOG
  2. +16 −5 pyechonest/util.py
  3. +1 −1 setup.py
View
@@ -1,3 +1,7 @@
+Rev 8.0.0 to 8.0.1
+
+EchoNestAPIError now reports the HTTP status code of the failed request.
+
Rev 7.1.1 to 8.0.0
Delete old deprecated playlist functions.
View
@@ -83,8 +83,15 @@ class EchoNestAPIError(EchoNestException):
"""
API Specific Errors.
"""
- def __init__(self, code, message, headers):
- formatted_message = ('Echo Nest API Error %d: %s' % (code, message),)
+ def __init__(self, code, message, headers, http_status):
+ if http_status:
+ http_status_message_part = ' [HTTP %d]' % http_status
+ else:
+ http_status_message_part = ''
+ self.http_status = http_status
+
+ formatted_message = ('Echo Nest API Error %d: %s%s' %
+ (code, message, http_status_message_part),)
super(EchoNestAPIError, self).__init__(code, formatted_message, headers)
class EchoNestIOError(EchoNestException):
@@ -96,10 +103,14 @@ def __init__(self, code=None, error=None, headers=headers):
super(EchoNestIOError, self).__init__(code, formatted_message, headers)
def get_successful_response(raw_json):
- if hasattr(raw_json,'headers'):
+ if hasattr(raw_json, 'headers'):
headers = raw_json.headers
else:
headers = {'Headers':'No Headers'}
+ if hasattr(raw_json, 'getcode'):
+ http_status = raw_json.getcode()
+ else:
+ http_status = None
raw_json = raw_json.read()
try:
response_dict = json.loads(raw_json)
@@ -108,12 +119,12 @@ def get_successful_response(raw_json):
message = status_dict['message']
if (code != 0):
# do some cute exception handling
- raise EchoNestAPIError(code, message, headers)
+ raise EchoNestAPIError(code, message, headers, http_status)
del response_dict['response']['status']
return response_dict
except ValueError:
logger.debug(traceback.format_exc())
- raise EchoNestAPIError(-1, "Unknown error.", headers)
+ raise EchoNestAPIError(-1, "Unknown error.", headers, http_status)
# These two functions are to deal with the unknown encoded output of codegen (varies by platform and ID3 tag)
View
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# encoding: utf-8
-__version__ = "8.0.0"
+__version__ = "8.0.1"
# $Source$
from sys import version

0 comments on commit 77a88af

Please sign in to comment.