Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added error propagation to gateway_request function #1233

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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