From 8294519f437bf880025118e1bfcb9ea50f93763f Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Wed, 1 Jun 2022 13:12:37 +0200 Subject: [PATCH] Content fetcher - Handle when a page doesnt load properly --- changedetectionio/content_fetcher.py | 12 ++++++++++++ changedetectionio/update_worker.py | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/changedetectionio/content_fetcher.py b/changedetectionio/content_fetcher.py index 78446f5b..6062e263 100644 --- a/changedetectionio/content_fetcher.py +++ b/changedetectionio/content_fetcher.py @@ -6,6 +6,14 @@ import requests import time import sys +class PageUnloadable(Exception): + def __init__(self, status_code, url): + # Set this so we can use it in other parts of the app + self.status_code = status_code + self.url = url + return + pass + class EmptyReply(Exception): def __init__(self, status_code, url): # Set this so we can use it in other parts of the app @@ -306,6 +314,10 @@ class base_html_playwright(Fetcher): context.close() browser.close() raise EmptyReply(url=url, status_code=None) + except Exception as e: + context.close() + browser.close() + raise PageUnloadable(url=url, status_code=None) if response is None: context.close() diff --git a/changedetectionio/update_worker.py b/changedetectionio/update_worker.py index 40a66a49..e110ef8c 100644 --- a/changedetectionio/update_worker.py +++ b/changedetectionio/update_worker.py @@ -67,6 +67,11 @@ class update_worker(threading.Thread): err_text = "Screenshot unavailable, page did not render fully in the expected time" self.datastore.update_watch(uuid=uuid, update_obj={'last_error': err_text, 'last_check_status': e.status_code}) + except content_fetcher.PageUnloadable as e: + err_text = "Page request from server didnt respond correctly" + self.datastore.update_watch(uuid=uuid, update_obj={'last_error': err_text, + 'last_check_status': e.status_code}) + except Exception as e: self.app.logger.error("Exception reached processing watch UUID: %s - %s", uuid, str(e)) self.datastore.update_watch(uuid=uuid, update_obj={'last_error': str(e)})