From ff88cb3ab642e62941fa995bd2fe4d09e95793d2 Mon Sep 17 00:00:00 2001 From: jreadey Date: Fri, 29 Mar 2024 05:02:40 -0700 Subject: [PATCH] added handlers for timeout error --- hsds/util/httpUtil.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/hsds/util/httpUtil.py b/hsds/util/httpUtil.py index df949c53..1dc2030d 100644 --- a/hsds/util/httpUtil.py +++ b/hsds/util/httpUtil.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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