better error

This commit is contained in:
dgtlmoon
2023-09-26 13:26:50 +02:00
parent 9b4fb80bef
commit 29d34bcd22
3 changed files with 17 additions and 6 deletions
+2 -1
View File
@@ -77,12 +77,13 @@ class ScreenshotUnavailable(Exception):
class ReplyWithContentButNoText(Exception):
def __init__(self, status_code, url, screenshot=None, has_filters=False):
def __init__(self, status_code, url, screenshot=None, has_filters=False, html_content=''):
# Set this so we can use it in other parts of the app
self.status_code = status_code
self.url = url
self.screenshot = screenshot
self.has_filters = has_filters
self.html_content = html_content
return
@@ -317,7 +317,8 @@ class perform_site_check(difference_detection_processor):
raise content_fetcher.ReplyWithContentButNoText(url=url,
status_code=fetcher.get_last_status_code(),
screenshot=screenshot,
has_filters=has_filter_rule and len(html_content)
has_filters=has_filter_rule,
html_content=html_content
)
# We rely on the actual text in the html output.. many sites have random script vars etc,
+13 -4
View File
@@ -3,7 +3,7 @@ import threading
import queue
import time
from changedetectionio import content_fetcher
from changedetectionio import content_fetcher, html_tools
from .processors.text_json_diff import FilterNotFoundInResponse
from .processors.restock_diff import UnableToExtractRestockData
@@ -251,10 +251,19 @@ class update_worker(threading.Thread):
# Totally fine, it's by choice - just continue on, nothing more to care about
# Page had elements/content but no renderable text
# Backend (not filters) gave zero output
extra_help = ""
if e.has_filters:
self.datastore.update_watch(uuid=uuid, update_obj={'last_error': f"Got HTML content but no text found (With {e.status_code} reply code), it's possible that the filters you have give an empty result or contain only an image <a href=\"https://github.com/dgtlmoon/changedetection.io/wiki/Detecting-changes-in-images\">more help here</a>"})
else:
self.datastore.update_watch(uuid=uuid, update_obj={'last_error': f"Got HTML content but no text found (With {e.status_code} reply code)."})
# Maybe it contains an image? offer a more helpful link
has_img = html_tools.include_filters(include_filters='img',
html_content=e.html_content)
if has_img:
extra_help = ", it's possible that the filters you have give an empty result or contain only an image <a href=\"https://github.com/dgtlmoon/changedetection.io/wiki/Detecting-changes-in-images\">more help here</a>"
else:
extra_help = ", it's possible that the filters were found, but contained no usable text"
self.datastore.update_watch(uuid=uuid, update_obj={
'last_error': f"Got HTML content but no text found (With {e.status_code} reply code){extra_help}"
})
if e.screenshot:
self.datastore.save_screenshot(watch_uuid=uuid, screenshot=e.screenshot)