diff options
-rw-r--r-- | README.md | 2 | ||||
-rwxr-xr-x | serve.py | 8 | ||||
-rw-r--r-- | tagrss.py | 10 |
3 files changed, 17 insertions, 3 deletions
@@ -15,8 +15,6 @@ See `LICENSE.txt` in the root of this repository for the text of the license. ## To do * Add JS to make the feed/tag input situation work like one would normally expect rather than like it's 1985. (Progressive enhancement, though.) -* Do more user input validation -* Handle more `requests` and `feedparser` error conditions * Add support for authentication * Allow specifying update interval on a per-feed basis @@ -228,6 +228,12 @@ def add_feed_effect(): ) else: raise bottle.HTTPError(500, f"Failed to fetch feed from {feed_source}.") + except tagrss.NotAFeedError: + raise bottle.HTTPError( + 400, + f"Could not add feed from {feed_source} as the content at the location is " + "not a valid feed.", + ) return bottle.template( "add_feed", after_add=True, @@ -316,7 +322,7 @@ def update_feeds(run_event: threading.Event): for feed in feeds: try: core.update_feed(feed.id) - except tagrss.FeedFetchError as e: + except (tagrss.FeedFetchError, tagrss.NotAFeedError) as e: logging.error( f"Failed to update feed {feed.id} with source {feed.source} " f"due to the following error: {e}." @@ -59,6 +59,10 @@ class FeedFetchError(Exception): super().__init__(f"Get {feed_source} failed: {underlying}") +class NotAFeedError(Exception): + pass + + FeedId = int Epoch = int ParsedFeed = feedparser.FeedParserDict @@ -431,6 +435,12 @@ class TagRss: io.BytesIO(bytes(response.text, encoding="utf-8")), response_headers={"Content-Location": base}, ) + if not ( + getattr(parsed.feed, "title", None) + or getattr(parsed.feed, "link", None) + or getattr(parsed.feed, "id", None) + ): + raise NotAFeedError(source) return (parsed, epoch_downloaded) def add_feed( |