exc-mw
All checks were successful
Deploy on push / deploy (push) Successful in 1m8s

This commit is contained in:
2024-06-04 08:10:57 +03:00
parent 231de135ca
commit d53256bcd7
4 changed files with 23 additions and 12 deletions

17
services/exception.py Normal file
View File

@@ -0,0 +1,17 @@
import logging
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.responses import JSONResponse
logger = logging.getLogger("exception")
logging.basicConfig(level=logging.DEBUG)
class ExceptionHandlerMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request, call_next):
try:
response = await call_next(request)
return response
except Exception as exc:
logger.exception(exc)
return JSONResponse({"detail": "An error occurred. Please try again later."}, status_code=500)

View File

@@ -66,15 +66,7 @@ root_logger = logging.getLogger()
root_logger.setLevel(logging.DEBUG)
root_logger.addHandler(stream)
ignore_logs = [
"_trace",
"httpx",
"_client",
"_trace.atrace",
"aiohttp",
"_client",
"base"
]
ignore_logs = ["_trace", "httpx", "_client", "_trace.atrace", "aiohttp", "_client", "base"]
for lgr in ignore_logs:
loggr = logging.getLogger(lgr)
loggr.setLevel(logging.INFO)

View File

@@ -180,7 +180,8 @@ class SearchService:
size=limit,
from_=offset,
_source=False,
_source_excludes=["title", "body", "subtitle", "media", "lead", "_index"])
_source_excludes=["title", "body", "subtitle", "media", "lead", "_index"],
)
hits = search_response["hits"]["hits"]
results = [{"id": hit["_id"], "score": hit["_score"]} for hit in hits]