From 5e77d799e1fe8e2d5b0545b329ef48dfb576e8a0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 1 Jan 2026 13:50:25 +0700 Subject: [PATCH] Fix: Indentation error in YouTubeService and Add Global Exception Handler --- backend/main.py | 13 +++++++++++++ backend/services/youtube.py | 1 + 2 files changed, 14 insertions(+) diff --git a/backend/main.py b/backend/main.py index 5e1f2dc..0a12a43 100644 --- a/backend/main.py +++ b/backend/main.py @@ -58,3 +58,16 @@ else: @app.get("/health") def health_check(): return {"status": "ok"} + +from fastapi import Request +from fastapi.responses import JSONResponse + +@app.exception_handler(Exception) +async def global_exception_handler(request: Request, exc: Exception): + import traceback + error_detail = "".join(traceback.format_exception(None, exc, exc.__traceback__)) + print(f"Global 500 Error: {error_detail}") + return JSONResponse( + status_code=500, + content={"message": "Internal Server Error", "detail": error_detail} + ) diff --git a/backend/services/youtube.py b/backend/services/youtube.py index 2976c85..eba6cc0 100644 --- a/backend/services/youtube.py +++ b/backend/services/youtube.py @@ -243,6 +243,7 @@ class YouTubeService: response = {"tracks": tracks} self.cache.set(cache_key, response, ttl_seconds=3600) return response + except Exception as e: print(f"Rec Error: {e}") return {"tracks": []}