From 406e96ce390d7eba139805072dbf3462f98ada3f Mon Sep 17 00:00:00 2001 From: inportb Date: Tue, 27 Sep 2022 21:34:41 -0400 Subject: [PATCH] Gracefully report backend failure to connect --- main.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 98207f4..d910f22 100644 --- a/main.py +++ b/main.py @@ -53,14 +53,18 @@ def application(): @app.post('/v1/vista') def cb_connect(): params = request.json['params'] - if params.get('secret') == secret: - cid = ''.join(secrets.choice(string.ascii_lowercase + string.digits) for i in range(64)) - while cid in clients: + try: + if params.get('secret') == secret: cid = ''.join(secrets.choice(string.ascii_lowercase + string.digits) for i in range(64)) - clients[cid] = client = CacheProxyRPC(rpc.ClientSync(host=params.get('host', 'test.northport.med.va.gov'), port=int(params.get('port', 19009)))) - return jsonify({ 'result': cid, 'error': None, 'id': request.json.get('id') }) - else: - return jsonify({ 'result': None, 'error': { 'type': 'Unauthorized', 'args': [] }, 'id': request.json.get('id') }) + while cid in clients: + cid = ''.join(secrets.choice(string.ascii_lowercase + string.digits) for i in range(64)) + clients[cid] = client = CacheProxyRPC(rpc.ClientSync(host=params.get('host', 'test.northport.med.va.gov'), port=int(params.get('port', 19009)))) + return jsonify({ 'result': cid, 'error': None, 'id': request.json.get('id') }) + else: + return jsonify({ 'result': None, 'error': { 'type': 'Unauthorized', 'args': [] }, 'id': request.json.get('id') }) + except Exception as ex: + logger.exception(request.url) + return jsonify({ 'result': None, 'error': { 'type': ex.__class__.__name__, 'args': ex.args }, 'id': request.json.get('id') }) @app.post('/v1/vista//close') def cb_close(cid):