From 9d8a61fa5cf49c3739e76456785784483e75bbc9 Mon Sep 17 00:00:00 2001 From: Daisie Huang Date: Wed, 23 Oct 2024 21:46:35 -0700 Subject: [PATCH] better error handling if a server fails to register --- candig_federation/operations.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/candig_federation/operations.py b/candig_federation/operations.py index 1d05f66..e9d9490 100644 --- a/candig_federation/operations.py +++ b/candig_federation/operations.py @@ -57,11 +57,18 @@ def add_server(register=False): try: # if register=True, list known servers in Vault and register them all if register: + errors = {} existing_servers = get_registered_servers() for server in existing_servers: - register_server(existing_servers[server]) + try: + register_server(existing_servers[server]) + except Exception as e: + logger.debug(f"failed to register {existing_servers[server]['server']['id']} {type(e)} {str(e)}", request) + errors[existing_servers[server]['server']['id']] = f"{type(e)} {str(e)}" + if len(errors) > 0: + return errors, 500 except Exception as e: - logger.debug(f"Couldn't register server", request) + logger.debug(f"Couldn't register servers: {type(e)} {str(e)}", request) return {"message": f"Couldn't register servers: {type(e)} {str(e)} {connexion.request}"}, 500 try: if connexion.request.json is not None and 'server' in connexion.request.json: