diff --git a/changedetectionio/processors/restock_diff.py b/changedetectionio/processors/restock_diff.py index b094797a..6caf82d7 100644 --- a/changedetectionio/processors/restock_diff.py +++ b/changedetectionio/processors/restock_diff.py @@ -12,6 +12,12 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) name = 'Re-stock detection for single product pages' description = 'Detects if the product goes back to in-stock' +class UnableToExtractRestockData(Exception): + def __init__(self, status_code): + # Set this so we can use it in other parts of the app + self.status_code = status_code + return + class perform_site_check(difference_detection_processor): screenshot = None xpath_data = None @@ -105,7 +111,8 @@ class perform_site_check(difference_detection_processor): fetched_md5 = hashlib.md5(fetcher.instock_data.encode('utf-8')).hexdigest() # 'Possibly in stock' comes from stock-not-in-stock.js when no string found above the fold. update_obj["in_stock"] = True if fetcher.instock_data == 'Possibly in stock' else False - + else: + raise UnableToExtractRestockData(status_code=fetcher.status_code) # The main thing that all this at the moment comes down to :) changed_detected = False diff --git a/changedetectionio/update_worker.py b/changedetectionio/update_worker.py index 95a584d9..e40d5c58 100644 --- a/changedetectionio/update_worker.py +++ b/changedetectionio/update_worker.py @@ -5,7 +5,7 @@ import time from changedetectionio import content_fetcher from .processors.text_json_diff import FilterNotFoundInResponse - +from .processors.restock_diff import UnableToExtractRestockData # A single update worker # @@ -319,6 +319,11 @@ class update_worker(threading.Thread): 'last_check_status': e.status_code, 'has_ldjson_price_data': None}) process_changedetection_results = False + except UnableToExtractRestockData as e: + # Usually when fetcher.instock_data returns empty + self.app.logger.error("Exception reached processing watch UUID: %s - %s", uuid, str(e)) + self.datastore.update_watch(uuid=uuid, update_obj={'last_error': f"Unable to extract restock data for this page unfortunately. (Got code {e.status_code} from server)"}) + process_changedetection_results = False 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)})