diff --git a/app/services/platforms/reddit_comment.py b/app/services/platforms/reddit_comment.py index 7461a6c..62794f1 100644 --- a/app/services/platforms/reddit_comment.py +++ b/app/services/platforms/reddit_comment.py @@ -73,8 +73,12 @@ def _find_sticky( """ # TODO: use session_file for authenticated requests on private subs url = f"https://www.reddit.com/r/{sub}/hot.json?limit=10" - response = httpx.get(url, headers={"User-Agent": "magpie/1.0"}) - response.raise_for_status() + try: + response = httpx.get(url, headers={"User-Agent": "magpie/1.0"}, timeout=10) + response.raise_for_status() + except httpx.HTTPError as exc: + logger.warning("Reddit hot.json request failed for r/%s: %s", sub, exc) + raise RuntimeError(f"Failed to fetch hot listing for r/{sub}") from exc payload = response.json() if "data" not in payload: logger.warning("Unexpected Reddit API response: %r", payload) diff --git a/tests/services/platforms/test_reddit_comment_strategy.py b/tests/services/platforms/test_reddit_comment_strategy.py index 9bc7513..6150bb6 100644 --- a/tests/services/platforms/test_reddit_comment_strategy.py +++ b/tests/services/platforms/test_reddit_comment_strategy.py @@ -9,7 +9,7 @@ def strategy(): return RedditCommentStrategy() -def test_execute_with_url_override(strategy, monkeypatch): +def test_execute_with_url_override(strategy): """Uses thread_url_override to get thread_id, calls client.comment()""" mock_client = MagicMock() mock_client.comment.return_value = "https://www.reddit.com/r/flipping/comments/abc123/_/xyz789/"