aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2023-08-04 16:39:08 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2023-08-04 16:39:08 +0000
commit8f5488436b90d85969abb8bdcbb0ecf14d8936bd (patch)
tree8fc1c4cb5201c344ea1a1586e19e1a50d4121f23
parentf8aa1606b8733f629762f54785660305d4eb636e (diff)
downloadtagrss-8f5488436b90d85969abb8bdcbb0ecf14d8936bd.tar
tagrss-8f5488436b90d85969abb8bdcbb0ecf14d8936bd.tar.gz
tagrss-8f5488436b90d85969abb8bdcbb0ecf14d8936bd.zip
Handle if a non-feed URL is given
-rw-r--r--README.md2
-rwxr-xr-xserve.py8
-rw-r--r--tagrss.py10
3 files changed, 17 insertions, 3 deletions
diff --git a/README.md b/README.md
index ece0e12..39b7e8b 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/serve.py b/serve.py
index 9ad398f..ee51c99 100755
--- a/serve.py
+++ b/serve.py
@@ -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}."
diff --git a/tagrss.py b/tagrss.py
index 9179035..ae9482c 100644
--- a/tagrss.py
+++ b/tagrss.py
@@ -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(