From 50741764d2adedbb4510c4bb69be1cb0ca9ceeb7 Mon Sep 17 00:00:00 2001 From: Dennis Yelizarov Date: Wed, 14 Sep 2016 10:45:19 -0400 Subject: [PATCH] dont throw an exception on a 204 --- zendesk/endpoints_v2.py | 7 ------- zendesk/zendesk.py | 17 ++++++----------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/zendesk/endpoints_v2.py b/zendesk/endpoints_v2.py index 9dda741..34a25fc 100644 --- a/zendesk/endpoints_v2.py +++ b/zendesk/endpoints_v2.py @@ -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 diff --git a/zendesk/zendesk.py b/zendesk/zendesk.py index 15b4960..afd4cb5 100755 --- a/zendesk/zendesk.py +++ b/zendesk/zendesk.py @@ -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 @@ -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: @@ -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 @@ -240,12 +239,8 @@ 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, [], (), {}) @@ -253,5 +248,5 @@ def _response_handler(response, content, status): return response.get('location') elif content.strip(): return json.loads(content) - else: - return responses[response_status] + + return responses[response.status]