From 67d32fecd60d5b4b919440718b2c275daf0b8c19 Mon Sep 17 00:00:00 2001 From: npeter83 Date: Tue, 18 Aug 2026 00:21:59 +0200 Subject: [PATCH] fix(search): return 422 not 502 on an upstream YouTube failure (B-core-1) /api/search/youtube raised 502 on an upstream error, but the frontend treats 502/503/504 as a gateway dropout: it auto-retries the GET (a second quota-costed search) and shows a "connection lost" banner instead of the real message. Every sibling upstream-error site already returns 422 for exactly this reason. Reserve 5xx for the raw byte-proxies. --- backend/app/routes/search.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/app/routes/search.py b/backend/app/routes/search.py index c0e3d012..75131d2e 100644 --- a/backend/app/routes/search.py +++ b/backend/app/routes/search.py @@ -268,7 +268,11 @@ def search_youtube( except (YouTubeError, search_scrape.ScrapeError) as exc: if collected: break # keep what we already gathered - raise HTTPException(status_code=502, detail=f"YouTube search failed: {exc}") + # 422, not 502: this is a JSON endpoint, and the FE treats 502/503/504 as a gateway + # dropout (auto-retry + "connection lost" banner — lib/api/core RETRIABLE_GATEWAY), + # which hides the real message and burns a second quota-costed search. Upstream failure + # on a JSON endpoint = 422 + message; reserve 5xx for the raw byte-proxies. (B-core-1) + raise HTTPException(status_code=422, detail=f"YouTube search failed: {exc}") from exc # Drop currently-live/upcoming, channel-less, and blocked-channel results. candidates = [