From 69c7a9b3d101799f6446c956d35590933898b4be Mon Sep 17 00:00:00 2001 From: vrubel Date: Fri, 2 Jan 2026 17:30:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA=20=D0=B8=20=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B2?= =?UTF-8?q?=20tmdb-proxy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tmdb-proxy/tmdb_proxy.py | 55 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/tmdb-proxy/tmdb_proxy.py b/tmdb-proxy/tmdb_proxy.py index 4f4d5a4..45daa4b 100644 --- a/tmdb-proxy/tmdb_proxy.py +++ b/tmdb-proxy/tmdb_proxy.py @@ -5,10 +5,15 @@ TMDB API Proxy Service """ import os +import logging import httpx from fastapi import FastAPI, HTTPException, Query from fastapi.middleware.cors import CORSMiddleware +# Настройка логирования +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + app = FastAPI(title="TMDB API Proxy", version="1.0.0") # Настройка CORS @@ -35,6 +40,7 @@ async def search_movies( """Прокси для поиска фильмов через TMDB API""" async with httpx.AsyncClient(timeout=30.0) as client: try: + logger.info(f"Searching TMDB for query: {query}") response = await client.get( f"{TMDB_BASE_URL}/search/movie", params={ @@ -46,9 +52,33 @@ async def search_movies( } ) response.raise_for_status() - return response.json() + data = response.json() + logger.info(f"TMDB search successful, found {data.get('total_results', 0)} results") + return data + except httpx.ConnectError as e: + logger.error(f"Connection error to TMDB API: {e}") + raise HTTPException( + status_code=503, + detail=f"Cannot connect to TMDB API. Check network connectivity and DNS. Error: {str(e)}" + ) + except httpx.TimeoutException as e: + logger.error(f"Timeout connecting to TMDB API: {e}") + raise HTTPException( + status_code=504, + detail=f"Timeout connecting to TMDB API: {str(e)}" + ) + except httpx.HTTPStatusError as e: + logger.error(f"TMDB API returned error status {e.response.status_code}: {e.response.text}") + raise HTTPException( + status_code=e.response.status_code, + detail=f"TMDB API error (status {e.response.status_code}): {e.response.text[:200]}" + ) except httpx.HTTPError as e: + logger.error(f"HTTP error: {e}") raise HTTPException(status_code=500, detail=f"TMDB API error: {str(e)}") + except Exception as e: + logger.error(f"Unexpected error: {e}", exc_info=True) + raise HTTPException(status_code=500, detail=f"Unexpected error: {str(e)}") @app.get("/movie/{movie_id}") @@ -60,6 +90,7 @@ async def get_movie_details( """Прокси для получения детальной информации о фильме из TMDB""" async with httpx.AsyncClient(timeout=30.0) as client: try: + logger.info(f"Fetching TMDB movie details for ID: {movie_id}") params = { "api_key": TMDB_API_KEY, "language": language @@ -73,8 +104,30 @@ async def get_movie_details( ) response.raise_for_status() return response.json() + except httpx.ConnectError as e: + logger.error(f"Connection error to TMDB API: {e}") + raise HTTPException( + status_code=503, + detail=f"Cannot connect to TMDB API. Check network connectivity and DNS. Error: {str(e)}" + ) + except httpx.TimeoutException as e: + logger.error(f"Timeout connecting to TMDB API: {e}") + raise HTTPException( + status_code=504, + detail=f"Timeout connecting to TMDB API: {str(e)}" + ) + except httpx.HTTPStatusError as e: + logger.error(f"TMDB API returned error status {e.response.status_code}: {e.response.text}") + raise HTTPException( + status_code=e.response.status_code, + detail=f"TMDB API error (status {e.response.status_code}): {e.response.text[:200]}" + ) except httpx.HTTPError as e: + logger.error(f"HTTP error: {e}") raise HTTPException(status_code=500, detail=f"TMDB API error: {str(e)}") + except Exception as e: + logger.error(f"Unexpected error: {e}", exc_info=True) + raise HTTPException(status_code=500, detail=f"Unexpected error: {str(e)}") @app.get("/health")