From d24db79c74a3d2edf2faedbf9112d67e4fac228a Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Fri, 31 May 2024 09:51:37 -0700 Subject: [PATCH] Retry backend request on 502 return --- neon_utils/hana_utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/neon_utils/hana_utils.py b/neon_utils/hana_utils.py index 3ed0204f..e113c8b8 100644 --- a/neon_utils/hana_utils.py +++ b/neon_utils/hana_utils.py @@ -162,9 +162,14 @@ def request_backend(endpoint: str, request_data: dict, except ServerException as e: LOG.error(e) _get_token(server_url) - resp = requests.post(f"{server_url}/{endpoint.lstrip('/')}", - json=request_data, headers=_headers) + request_kwargs = {"url": f"{server_url}/{endpoint.lstrip('/')}", + "json": request_data, "headers": _headers} + resp = requests.post(**request_kwargs) + if resp.status_code == 502: + # This is raised occasionally on valid requests. Need to resolve in HANA + resp = requests.post(**request_kwargs) if resp.ok: return resp.json() + else: raise ServerException(f"Error response {resp.status_code}: {resp.text}")