From 9d5e1f6bb6a0cb591cf77c02cc365c190093518d Mon Sep 17 00:00:00 2001 From: Broden Wanner Date: Tue, 7 Mar 2023 16:11:43 -0600 Subject: [PATCH] Added error propagation to gateway_request function (#1233) Co-authored-by: BrodyWanner --- jupyter_server/gateway/gateway_client.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/jupyter_server/gateway/gateway_client.py b/jupyter_server/gateway/gateway_client.py index 8444a4cddb..1d2b420f50 100644 --- a/jupyter_server/gateway/gateway_client.py +++ b/jupyter_server/gateway/gateway_client.py @@ -728,9 +728,19 @@ async def gateway_request(endpoint: str, **kwargs: ty.Any) -> HTTPResponse: # NOTE: We do this here since this handler is called during the server's startup and subsequent refreshes # of the tree view. except HTTPClientError as e: + error_reason = f"Exception while attempting to connect to Gateway server url '{GatewayClient.instance().url}'" + error_message = e.message + if e.response: + try: + error_payload = json.loads(e.response.body) + error_reason = error_payload.get("reason") or error_reason + error_message = error_payload.get("message") or error_message + except json.decoder.JSONDecodeError: + error_reason = e.response.body.decode() + raise web.HTTPError( e.code, - f"Error attempting to connect to Gateway server url '{GatewayClient.instance().url}'. " + f"Error from Gateway: [{error_message}] {error_reason}. " "Ensure gateway url is valid and the Gateway instance is running.", ) from e except ConnectionError as e: