Skip to content

Commit e38b2dc

Browse files
committed
Fix mypy and logger for common exceptions
1 parent 16f8bbe commit e38b2dc

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

brood/db.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
Connections to external services
33
"""
4+
from typing import Optional
5+
46
from sqlalchemy import create_engine
57
from sqlalchemy.orm.session import Session, sessionmaker
68

@@ -12,7 +14,7 @@
1214
)
1315

1416

15-
def create_brood_engine(url: str, pool_size: int, statement_timeout: int):
17+
def create_brood_engine(url: Optional[str], pool_size: int, statement_timeout: int):
1618
# Pooling: https://docs.sqlalchemy.org/en/14/core/pooling.html#sqlalchemy.pool.QueuePool
1719
# Statement timeout: https://stackoverflow.com/a/44936982
1820
return create_engine(

brood/middleware.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from typing import Optional, Union
23
from uuid import UUID
34

@@ -14,6 +15,8 @@
1415
from .db import yield_db_read_only_session
1516
from .settings import BOT_INSTALLATION_TOKEN, BOT_INSTALLATION_TOKEN_HEADER
1617

18+
logger = logging.getLogger(__name__)
19+
1720
# Login implementation follows:
1821
# https://fastapi.tiangolo.com/tutorial/security/simple-oauth2/
1922
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
@@ -29,6 +32,7 @@ async def get_current_user(
2932
except actions.TokenNotFound:
3033
raise HTTPException(status_code=404, detail="Access token not found")
3134
except Exception:
35+
logger.error("Unhandled exception at get_current_user")
3236
raise HTTPException(status_code=500)
3337
if not token_object.active:
3438
raise HTTPException(status_code=403, detail="Token has expired")
@@ -46,6 +50,7 @@ async def get_current_user_with_groups(
4650
except actions.TokenNotFound:
4751
raise HTTPException(status_code=404, detail="Access token not found")
4852
except Exception:
53+
logger.error("Unhandled exception at get_current_user_with_groups")
4954
raise HTTPException(status_code=500)
5055
if not token_active:
5156
raise HTTPException(status_code=403, detail="Token has expired")
@@ -123,5 +128,6 @@ async def is_token_restricted(
123128
except actions.TokenNotFound:
124129
raise HTTPException(status_code=404, detail="Access token not found")
125130
except Exception:
131+
logger.error("Unhandled exception at is_token_restricted")
126132
raise HTTPException(status_code=500)
127133
return token_object.restricted

0 commit comments

Comments
 (0)