Skip to content

Commit

Permalink
fix getDetails JSON error on 5xx status code
Browse files Browse the repository at this point in the history
  • Loading branch information
PriOliveira authored and max-ipinfo committed Aug 3, 2024
1 parent e1c2d5f commit 0a7222e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion ipinfo/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 5 additions & 1 deletion ipinfo/handler_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 0a7222e

Please sign in to comment.