Fix: Indentation error in YouTubeService and Add Global Exception Handler

This commit is contained in:
Your Name 2026-01-01 13:50:25 +07:00
parent c23395e225
commit 5e77d799e1
2 changed files with 14 additions and 0 deletions

View file

@ -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}
)

View file

@ -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": []}