@@ -282,18 +282,23 @@ def gateway_request(endpoint, **kwargs):
282282 # or the server is not running.
283283 # NOTE: We do this here since this handler is called during the Notebook's startup and subsequent refreshes
284284 # of the tree view.
285- except ConnectionRefusedError :
286- raise web .HTTPError (503 , "Connection refused from Gateway server url '{}'. "
287- "Check to be sure the Gateway instance is running." .format (GatewayClient .instance ().url ))
285+ except ConnectionRefusedError as e :
286+ raise web .HTTPError (
287+ 503 ,
288+ "Connection refused from Gateway server url '{}'. Check to be sure the"
289+ " Gateway instance is running." .format (GatewayClient .instance ().url )
290+ ) from e
288291 except HTTPError as e :
289292 # This can occur if the host is valid (e.g., foo.com) but there's nothing there.
290293 raise web .HTTPError (e .code , "Error attempting to connect to Gateway server url '{}'. "
291294 "Ensure gateway url is valid and the Gateway instance is running." .
292- format (GatewayClient .instance ().url ))
293- except gaierror :
294- raise web .HTTPError (404 , "The Gateway server specified in the gateway_url '{}' doesn't appear to be valid. "
295- "Ensure gateway url is valid and the Gateway instance is running." .
296- format (GatewayClient .instance ().url ))
295+ format (GatewayClient .instance ().url )) from e
296+ except gaierror as e :
297+ raise web .HTTPError (
298+ 404 ,
299+ "The Gateway server specified in the gateway_url '{}' doesn't appear to be valid. Ensure gateway "
300+ "url is valid and the Gateway instance is running." .format (GatewayClient .instance ().url )
301+ ) from e
297302
298303 raise gen .Return (response )
299304
@@ -575,8 +580,10 @@ def get_kernel_spec(self, kernel_name, **kwargs):
575580 if error .status_code == 404 :
576581 # Convert not found to KeyError since that's what the Notebook handler expects
577582 # message is not used, but might as well make it useful for troubleshooting
578- raise KeyError ('kernelspec {kernel_name} not found on Gateway server at: {gateway_url}' .
579- format (kernel_name = kernel_name , gateway_url = GatewayClient .instance ().url ))
583+ raise KeyError (
584+ 'kernelspec {kernel_name} not found on Gateway server at: {gateway_url}' .
585+ format (kernel_name = kernel_name , gateway_url = GatewayClient .instance ().url )
586+ ) from error
580587 else :
581588 raise
582589 else :
0 commit comments