diff --git a/app/api.py b/app/api.py index ac0814e..5ec0059 100644 --- a/app/api.py +++ b/app/api.py @@ -42,7 +42,7 @@ async def list_locations( return items -@api.get('/diyanet/search', response_model=List[PrayerTimes]) +@api.get('/diyanet/search', response_model=List[Location]) async def search_location( q: str, conn: sqlite3.Connection = Depends(get_connection)): diff --git a/app/app.py b/app/app.py index 213ec5b..517a52d 100644 --- a/app/app.py +++ b/app/app.py @@ -1,6 +1,16 @@ from fastapi import FastAPI +from loguru import logger +from starlette.requests import Request from app.api import api as api_router app = FastAPI() app.include_router(api_router, prefix='/api') + + +@app.exception_handler(Exception) +async def log_exceptions(req: Request, err: Exception): + try: + raise err + except: + logger.exception(err) diff --git a/core/diyanetdb.py b/core/diyanetdb.py index 04939ef..8e84fa3 100644 --- a/core/diyanetdb.py +++ b/core/diyanetdb.py @@ -99,7 +99,7 @@ def find_location_by_name(conn: sqlite3.Connection, q: str) -> List[Location]: WHERE locations_search match :q ORDER BY country, city, region ''' - stmt = conn.execute(sql, {'q': f'%{q}%'}) + stmt = conn.execute(sql, {'q': f'{q}'}) rows = stmt.fetchall() if not rows: return []