Skip to content

Commit

Permalink
Backport PR #1233 on branch 1.x (Added error propagation to gateway_r…
Browse files Browse the repository at this point in the history
…equest function) (#1234)Co-authored-by: Broden Wanner <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Steven Silvester <[email protected]>

* Backport PR #1233: Added error propagation to gateway_request function

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* lint

---------

Co-authored-by: Broden Wanner <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Steven Silvester <[email protected]>
  • Loading branch information
4 people authored Mar 8, 2023
1 parent a777102 commit 513df71
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file.

### Bugs fixed

- Backport PR #1212: Redact tokens, etc. in url parameters from request logs [#1214](https://github.com/jupyter-server/jupyter_server/pull/1214) ([@blink1073](https://github.com/blink1073))
- Backport PR #1212: Redact tokens, etc. in url parameters from request logs [#1214](https://github.com/jupyter-server/jupyter_server/pull/1214) ([@blink1073](https://github.com/blink1073))
- Backport PR #1193: Fix get_loader returning None when load_jupyter_server_extension is not found (#1193) (#1199)Co-authored-by: Steven Silvester <[email protected]> Co-authored-by: pre-commit-ci\[bot\] \<66853113+pre-commit-ci\[bot\]@users.noreply.github.com> [#1199](https://github.com/jupyter-server/jupyter_server/pull/1199) ([@cmd-ntrf](https://github.com/cmd-ntrf))

### Documentation improvements
Expand Down
12 changes: 11 additions & 1 deletion jupyter_server/gateway/gateway_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,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 = str(e)
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 513df71

Please sign in to comment.