Skip to content

Commit

Permalink
Added error propagation to gateway_request function (#1233)
Browse files Browse the repository at this point in the history
Co-authored-by: BrodyWanner <broden.wanner@target.com>
  • Loading branch information
broden-wanner and BrodyWanner authored Mar 7, 2023
1 parent 4513527 commit 9d5e1f6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion jupyter_server/gateway/gateway_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9d5e1f6

Please sign in to comment.