Skip to content

Commit 9904ac3

Browse files
authored
Merge pull request #65 from ipinfo/umar/handle-timeout-error
handled timeout error
2 parents e7ffe8d + 46acfbf commit 9904ac3

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

ipinfo/handler.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,12 @@ def getBatchDetails(
204204
chunk = lookup_addresses[i : i + batch_size]
205205

206206
# lookup
207-
response = requests.post(
208-
url, json=chunk, headers=headers, **req_opts
209-
)
207+
try:
208+
response = requests.post(
209+
url, json=chunk, headers=headers, **req_opts
210+
)
211+
except Exception as e:
212+
return handler_utils.return_or_fail(raise_on_fail, e, result)
210213

211214
# fail on bad status codes
212215
try:

ipinfo/handler_async.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,15 @@ async def _do_batch_req(
264264
"""
265265
Coroutine which will do the actual POST request for getBatchDetails.
266266
"""
267-
resp = await self.httpsess.post(
268-
url,
269-
data=json.dumps(chunk),
270-
headers=headers,
271-
timeout=timeout_per_batch,
272-
)
267+
try:
268+
resp = await self.httpsess.post(
269+
url,
270+
data=json.dumps(chunk),
271+
headers=headers,
272+
timeout=timeout_per_batch,
273+
)
274+
except Exception as e:
275+
return handler_utils.return_or_fail(raise_on_fail, e, None)
273276

274277
# gather data
275278
try:

0 commit comments

Comments
 (0)