From 170b570cbc9afed53c5ef76683d2ecf522c70d05 Mon Sep 17 00:00:00 2001 From: Trevin Chow Date: Sun, 17 May 2026 01:29:41 -0700 Subject: [PATCH] fix(reddit): re-raise HTTP 402 so fallback chain triggers The ScrapeCreators 402 (payment required / credits exhausted) status was being swallowed by the broad except Exception handlers in _global_search, _subreddit_search, and fetch_post_comments, returning [] instead of propagating. That caused users with exhausted credits to silently get zero Reddit results instead of falling through to the OpenAI / public Reddit JSON fallback chain in _search_reddit_thread. Add 402 to the existing 401/403 re-raise list across all three ScrapeCreators call paths. Closes #170. Co-authored-by: Jonathan Oppenheim --- skills/last30days/scripts/lib/reddit.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/skills/last30days/scripts/lib/reddit.py b/skills/last30days/scripts/lib/reddit.py index 66e1dc0..bd36a6b 100644 --- a/skills/last30days/scripts/lib/reddit.py +++ b/skills/last30days/scripts/lib/reddit.py @@ -334,7 +334,7 @@ def _global_search( ) return data.get("posts", data.get("data", [])) except http.HTTPError as e: - if e.status_code in (401, 403): + if e.status_code in (401, 402, 403): raise _log(f"Global search error: {e}") return [] @@ -376,6 +376,11 @@ def _subreddit_search( retries=2, ) return data.get("posts", data.get("data", [])) + except http.HTTPError as e: + if e.status_code in (401, 402, 403): + raise + _log(f"Subreddit search error for r/{subreddit}: {e}") + return [] except Exception as e: _log(f"Subreddit search error for r/{subreddit}: {e}") return [] @@ -403,6 +408,11 @@ def fetch_post_comments( retries=2, ) return data.get("comments", data.get("data", [])) + except http.HTTPError as e: + if e.status_code in (401, 402, 403): + raise + _log(f"Comment fetch error: {e}") + return [] except Exception as e: _log(f"Comment fetch error: {e}") return []