From f5c1c14c4d47413df737d3c050dd0e6d018467ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 23 Feb 2023 18:47:16 +0100 Subject: [PATCH] fix: Properly handle the optional responses --- website/web/__init__.py | 8 ++++++-- website/web/genericapi.py | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/website/web/__init__.py b/website/web/__init__.py index e8e24313..4d4de839 100644 --- a/website/web/__init__.py +++ b/website/web/__init__.py @@ -633,8 +633,12 @@ def monitor(tree_uuid: str): collection: str = request.form['collection'] if request.form.get('collection') else '' frequency: str = request.form['frequency'] if request.form.get('frequency') else 'daily' cache = lookyloo.capture_cache(tree_uuid) - monitoring_uuid = lookyloo.monitoring.monitor({'url': cache.url}, frequency=frequency, collection=collection) - flash(f"Sent to monitoring: {monitoring_uuid}", 'success') + if cache: + monitoring_uuid = lookyloo.monitoring.monitor({'url': cache.url, 'user_agent': cache.user_agent}, + frequency=frequency, collection=collection) + flash(f"Sent to monitoring: {monitoring_uuid}", 'success') + else: + flash(f"Unable to send to monitoring, uuid {tree_uuid} not found in cache.", 'error') return redirect(url_for('tree', tree_uuid=tree_uuid)) diff --git a/website/web/genericapi.py b/website/web/genericapi.py index 9da294b8..b2b726ae 100644 --- a/website/web/genericapi.py +++ b/website/web/genericapi.py @@ -462,9 +462,12 @@ class CompareCaptures(Resource): result = comparator.compare_captures(left_uuid, right_uuid) except MissingUUID as e: # UUID non-existent, or capture still ongoing. - status_left = lookyloo.get_capture_status(left_uuid) - status_right = lookyloo.get_capture_status(right_uuid) - return {'error': e, 'details': {left_uuid: status_left, right_uuid: status_right}} + if left_uuid and right_uuid: + status_left = lookyloo.get_capture_status(left_uuid) + status_right = lookyloo.get_capture_status(right_uuid) + return {'error': e, 'details': {left_uuid: status_left, right_uuid: status_right}} + else: + return {'error': e, 'details': 'Invalid request (left/right UUIDs missing.)'} return result