Skip to content

Commit 7bb21b4

Browse files
authored
Fix log arguments for gateway client error (jupyter-server#1385)
1 parent 359148b commit 7bb21b4

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

jupyter_server/gateway/gateway_client.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -757,22 +757,25 @@ async def _is_retryable(self, method: str, exception: Exception) -> bool:
757757

758758
async def gateway_request(endpoint: str, **kwargs: ty.Any) -> HTTPResponse:
759759
"""Make an async request to kernel gateway endpoint, returns a response"""
760-
kwargs = GatewayClient.instance().load_connection_args(**kwargs)
760+
gateway_client = GatewayClient.instance()
761+
kwargs = gateway_client.load_connection_args(**kwargs)
761762
rhc = RetryableHTTPClient()
762763
try:
763764
response = await rhc.fetch(endpoint, **kwargs)
764-
GatewayClient.instance().emit(
765+
gateway_client.emit(
765766
data={STATUS_KEY: SUCCESS_STATUS, STATUS_CODE_KEY: 200, MESSAGE_KEY: "success"}
766767
)
767768
# Trap a set of common exceptions so that we can inform the user that their Gateway url is incorrect
768769
# or the server is not running.
769770
# NOTE: We do this here since this handler is called during the server's startup and subsequent refreshes
770771
# of the tree view.
771772
except HTTPClientError as e:
772-
GatewayClient.instance().emit(
773+
gateway_client.emit(
773774
data={STATUS_KEY: ERROR_STATUS, STATUS_CODE_KEY: e.code, MESSAGE_KEY: str(e.message)}
774775
)
775-
error_reason = f"Exception while attempting to connect to Gateway server url '{GatewayClient.instance().url}'"
776+
error_reason = (
777+
f"Exception while attempting to connect to Gateway server url '{gateway_client.url}'"
778+
)
776779
error_message = e.message
777780
if e.response:
778781
try:
@@ -788,38 +791,39 @@ async def gateway_request(endpoint: str, **kwargs: ty.Any) -> HTTPResponse:
788791
"Ensure gateway url is valid and the Gateway instance is running.",
789792
) from e
790793
except ConnectionError as e:
791-
GatewayClient.instance().emit(
794+
gateway_client.emit(
792795
data={STATUS_KEY: ERROR_STATUS, STATUS_CODE_KEY: 503, MESSAGE_KEY: str(e)}
793796
)
794797
raise web.HTTPError(
795798
503,
796-
f"ConnectionError was received from Gateway server url '{GatewayClient.instance().url}'. "
799+
f"ConnectionError was received from Gateway server url '{gateway_client.url}'. "
797800
"Check to be sure the Gateway instance is running.",
798801
) from e
799802
except gaierror as e:
800-
GatewayClient.instance().emit(
803+
gateway_client.emit(
801804
data={STATUS_KEY: ERROR_STATUS, STATUS_CODE_KEY: 404, MESSAGE_KEY: str(e)}
802805
)
803806
raise web.HTTPError(
804807
404,
805-
f"The Gateway server specified in the gateway_url '{GatewayClient.instance().url}' doesn't "
808+
f"The Gateway server specified in the gateway_url '{gateway_client.url}' doesn't "
806809
f"appear to be valid. Ensure gateway url is valid and the Gateway instance is running.",
807810
) from e
808811
except Exception as e:
809-
GatewayClient.instance().emit(
812+
gateway_client.emit(
810813
data={STATUS_KEY: ERROR_STATUS, STATUS_CODE_KEY: 505, MESSAGE_KEY: str(e)}
811814
)
812815
logging.getLogger("ServerApp").error(
813-
f"Exception while trying to launch kernel via Gateway URL {GatewayClient.instance().url} , {e}",
816+
"Exception while trying to launch kernel via Gateway URL %s: %s",
817+
gateway_client.url,
814818
e,
815819
)
816820
raise e
817821

818-
if GatewayClient.instance().accept_cookies:
822+
if gateway_client.accept_cookies:
819823
# Update cookies on GatewayClient from server if configured.
820824
cookie_values = response.headers.get("Set-Cookie")
821825
if cookie_values:
822826
cookie: SimpleCookie = SimpleCookie()
823827
cookie.load(cookie_values)
824-
GatewayClient.instance().update_cookies(cookie)
828+
gateway_client.update_cookies(cookie)
825829
return response

0 commit comments

Comments
 (0)