aboutsummaryrefslogtreecommitdiff
path: root/tagrss.py
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2023-08-03 22:50:42 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2023-08-03 22:50:42 +0000
commit8728aef0b53677d1198e0e3e65207710a02aa9dc (patch)
tree5c826721fe455856fa1febad8f9d9f3a3e86be8b /tagrss.py
parent353001c9258de2cd1f8fcc026ea954cae624f669 (diff)
downloadtagrss-8728aef0b53677d1198e0e3e65207710a02aa9dc.tar
tagrss-8728aef0b53677d1198e0e3e65207710a02aa9dc.tar.gz
tagrss-8728aef0b53677d1198e0e3e65207710a02aa9dc.zip
Improve handling of network errors
Diffstat (limited to 'tagrss.py')
-rw-r--r--tagrss.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/tagrss.py b/tagrss.py
index ce67047..4370b7a 100644
--- a/tagrss.py
+++ b/tagrss.py
@@ -33,18 +33,28 @@ class FeedTitleAlreadyInUseError(StorageError):
class StorageConstraintViolationError(StorageError):
pass
+
class SqliteMissingForeignKeySupportError(StorageError):
pass
class FeedFetchError(Exception):
- def __init__(self, *, feed_source: str, status_code: typing.Optional[int] = None, underlying: typing.Optional[Exception] = None):
+ def __init__(
+ self,
+ *,
+ feed_source: str,
+ bad_source: bool = False,
+ status_code: typing.Optional[int] = None,
+ underlying: typing.Optional[Exception] = None,
+ ):
+ self.bad_source = bad_source
if status_code:
self.status_code = status_code
super().__init__(f"Get {feed_source} returned HTTP {status_code}")
else:
super().__init__(f"Get {feed_source} failed: {underlying}")
+
FeedId = int
Epoch = int
ParsedFeed = feedparser.FeedParserDict
@@ -398,9 +408,13 @@ class TagRss:
response = requests.get(source)
except requests.ConnectionError as e:
raise FeedFetchError(feed_source=source, underlying=e)
+ except requests.exceptions.MissingSchema as e:
+ raise FeedFetchError(feed_source=source, bad_source=True, underlying=e)
epoch_downloaded: int = int(time.time())
if response.status_code != requests.codes.ok:
- raise FeedFetchError(feed_source=source, status_code=response.status_code)
+ raise FeedFetchError(
+ feed_source=source, bad_source=True, status_code=response.status_code
+ )
try:
base: str = response.headers["Content-Location"]
except KeyError: