From 1d70af46846292e139fa93322accc2da625b7444 Mon Sep 17 00:00:00 2001 From: CREDO23 Date: Tue, 16 Jun 2026 19:12:09 +0200 Subject: [PATCH] fix(podcasts): guard public stream against missing audio --- surfsense_backend/app/routes/public_chat_routes.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/surfsense_backend/app/routes/public_chat_routes.py b/surfsense_backend/app/routes/public_chat_routes.py index 53f4c2651..516e976e6 100644 --- a/surfsense_backend/app/routes/public_chat_routes.py +++ b/surfsense_backend/app/routes/public_chat_routes.py @@ -103,8 +103,14 @@ async def stream_public_podcast( if storage_key: from app.file_storage.factory import get_storage_backend + backend = get_storage_backend() + # Verify first so a missing object is a 404, not a mid-stream crash. + if not await backend.exists(storage_key): + raise HTTPException( + status_code=404, detail="Podcast audio is no longer available" + ) return StreamingResponse( - get_storage_backend().open_stream(storage_key), + backend.open_stream(storage_key), media_type="audio/mpeg", headers={"Accept-Ranges": "bytes"}, )