Skip to content

Commit

Permalink
dont throw an exception on a 204
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-y committed Sep 14, 2016
1 parent aa35617 commit 5074176
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
7 changes: 0 additions & 7 deletions zendesk/endpoints_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,3 @@
'method': 'DELETE',
},
}

# Patch mapping table with correct HTTP Status expected
for method, api_map in mapping_table.items():
status = 200
if method.startswith('create_'):
status = 201
api_map['status'] = status
17 changes: 6 additions & 11 deletions zendesk/zendesk.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ def call(self, **kwargs):
path = "/api/v2" + path

method = api_map['method']
status = api_map['status']
valid_params = api_map.get('valid_params', ())
# Body can be passed from data or in args
body = kwargs.pop('data', None) or self.data
Expand Down Expand Up @@ -219,7 +218,7 @@ def call(self, **kwargs):
headers=self.headers
)
# Use a response handler to determine success/fail
return self._response_handler(response, content, status)
return self._response_handler(response, content)

# Missing method is also not defined in our mapping table
if api_call not in self.mapping_table:
Expand All @@ -229,7 +228,7 @@ def call(self, **kwargs):
return call.__get__(self)

@staticmethod
def _response_handler(response, content, status):
def _response_handler(response, content):
"""
Handle response as callback
Expand All @@ -240,18 +239,14 @@ def _response_handler(response, content, status):
ticket/group/etc and they pass this through 'location'. Otherwise,
the body of 'content' has our response.
"""
# Just in case
if not response:
raise ZendeskError('Response Not Found')
response_status = int(response.get('status', 0))
if response_status != status:
raise ZendeskError(content, response_status)
if response.status >= 400:
return responses[response.status]

# Deserialize json content if content exist. In some cases Zendesk
# returns ' ' strings. Also return false non strings (0, [], (), {})
if response.get('location'):
return response.get('location')
elif content.strip():
return json.loads(content)
else:
return responses[response_status]

return responses[response.status]

0 comments on commit 5074176

Please sign in to comment.