From bbfa02a607a784333cc281c7d7c838cbe8512fee Mon Sep 17 00:00:00 2001 From: Thomas Kluyver <thomas@kluyver.me.uk> Date: Mon, 8 Jan 2024 16:14:41 +0000 Subject: [PATCH] Informative error message when exflcalproxy is not available --- src/cal_tools/calcat_interface2.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/cal_tools/calcat_interface2.py b/src/cal_tools/calcat_interface2.py index bd9853141..3fa0b6167 100644 --- a/src/cal_tools/calcat_interface2.py +++ b/src/cal_tools/calcat_interface2.py @@ -15,6 +15,10 @@ import requests from oauth2_xfel_client import Oauth2ClientBackend +# Default address to connect to, only available internally +CALCAT_PROXY_URL = "http://exflcalproxy.desy.de:8080/" + + class ModuleNameError(KeyError): def __init__(self, name): self.name = name @@ -158,7 +162,7 @@ global_client = None def get_client(): global global_client if global_client is None: - setup_client("http://exflcalproxy:8080/", None, None, None) + setup_client(CALCAT_PROXY_URL, None, None, None) return global_client @@ -193,6 +197,20 @@ def setup_client( user_email=user_email, ) + # Check we can connect to exflcalproxy + if oauth_client is None and base_url == CALCAT_PROXY_URL: + try: + # timeout=(connect_timeout, read_timeout) + global_client.get_request('me', timeout=(1, 5)) + except requests.ConnectionError as e: + raise RuntimeError( + "Could not connect to calibration catalog proxy. This proxy allows " + "unauthenticated access inside the XFEL/DESY network. To look up " + "calibration constants from outside, you will need to create an Oauth " + "client ID & secret in the CalCat web interface. You will still not " + "be able to load constants without the constant store folder." + ) from e + _default_caldb_root = ... -- GitLab