Skip to content

Commit

Permalink
feat(error handle): handle none 200 responses from api
Browse files Browse the repository at this point in the history
- Raise descriptive error when response is not a 2xx
  • Loading branch information
Nick011 committed Oct 20, 2016
1 parent 10a716a commit c506db0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ubersmith/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ def process_request(self, method, data=None):

resp = BaseResponse(response)

if not str(response.status_code).startswith('2'):
error = '\nSTATUS CODE: {}\nCONTENT: {}'.format(
response.status_code,
str(response.content)
)
raise ResponseError(error)

# test for error in json response
if response.headers.get('content-type') == 'application/json':
if not resp.json.get('status'):
Expand All @@ -284,7 +291,7 @@ def process_request(self, method, data=None):
@staticmethod
def _is_token_response(response):
return ('text/html' in response.headers.get('content-type', '') and
'Updating Token' in response.content)
'Updating Token' in str(response.content))

def _send_request(self, method, data):
url = append_qs(self.base_url, {'method': method})
Expand Down

0 comments on commit c506db0

Please sign in to comment.