diff --git a/ipinfo/handler.py b/ipinfo/handler.py index a4afd12..507c810 100644 --- a/ipinfo/handler.py +++ b/ipinfo/handler.py @@ -123,8 +123,12 @@ def getDetails(self, ip_address=None, timeout=None): if response.status_code == 429: raise RequestQuotaExceededError() if response.status_code >= 400: - error_response = response.json() error_code = response.status_code + content_type = response.headers.get('Content-Type') + if content_type == 'application/json': + error_response = response.json() + else: + error_response = {'error': response.text} raise APIError(error_code, error_response) details = response.json() diff --git a/ipinfo/handler_async.py b/ipinfo/handler_async.py index 242728f..c71357a 100644 --- a/ipinfo/handler_async.py +++ b/ipinfo/handler_async.py @@ -145,8 +145,12 @@ async def getDetails(self, ip_address=None, timeout=None): if resp.status == 429: raise RequestQuotaExceededError() if resp.status >= 400: - error_response = await resp.json() error_code = resp.status + content_type = resp.headers.get('Content-Type') + if content_type == 'application/json': + error_response = await resp.json() + else: + error_response = {'error': resp.text()} raise APIError(error_code, error_response) details = await resp.json()