Skip to content

Commit

Permalink
added handlers for timeout error
Browse files Browse the repository at this point in the history
  • Loading branch information
jreadey committed Mar 29, 2024
1 parent fdc2c37 commit ff88cb3
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion hsds/util/httpUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# httpUtil:
# http-related helper functions
#
from asyncio import CancelledError
from asyncio import CancelledError, TimeoutError
import os
import socket
import numpy as np
Expand Down Expand Up @@ -327,6 +327,12 @@ async def http_get(app, url, params=None, client=None):
except CancelledError as cle:
log.warn(f"CancelledError for http_get({url}): {cle}")
raise HTTPInternalServerError()
except ConnectionResetError as cre:
log.warn(f"ConnectionResetError for http_get({url}): {cre}")
raise HTTPInternalServerError()
except TimeoutError as toe:
log.warn(f"TimeoutError for http_get({url}: {toe})")
raise HTTPServiceUnavailable()

return retval

Expand Down Expand Up @@ -402,6 +408,12 @@ async def http_post(app, url, data=None, params=None, client=None):
except CancelledError as cle:
log.warn(f"CancelledError for http_post({url}): {cle}")
raise HTTPInternalServerError()
except ConnectionResetError as cre:
log.warn(f"ConnectionResetError for http_post({url}): {cre}")
raise HTTPInternalServerError()
except TimeoutError as toe:
log.warn(f"TimeoutError for http_post({url}: {toe})")
raise HTTPServiceUnavailable()

return retval

Expand Down Expand Up @@ -459,6 +471,12 @@ async def http_put(app, url, data=None, params=None, client=None):
except CancelledError as cle:
log.warn(f"CancelledError for http_put({url}): {cle}")
raise HTTPInternalServerError()
except ConnectionResetError as cre:
log.warn(f"ConnectionResetError for http_put({url}): {cre}")
raise HTTPInternalServerError()
except TimeoutError as toe:
log.warn(f"TimeoutError for http_put({url}: {toe})")
raise HTTPServiceUnavailable()
return retval


Expand Down Expand Up @@ -507,6 +525,11 @@ async def http_delete(app, url, data=None, params=None, client=None):
except ConnectionResetError as cre:
log.warn(f"ConnectionResetError for http_delete({url}): {cre}")
raise HTTPInternalServerError()
except TimeoutError as toe:
log.warn(f"TimeoutError for http_delete({url}: {toe})")
raise HTTPServiceUnavailable()



return rsp_json

Expand Down

0 comments on commit ff88cb3

Please sign in to comment.