Skip to content

Commit 5d3d731

Browse files
committed
use GenotypeDBError
1 parent eb7aa28 commit 5d3d731

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

genotype_api/api/middleware.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from fastapi import Request
22
from starlette.middleware.base import BaseHTTPMiddleware
3-
4-
from genotype_api.database.database import close_session, get_session
3+
from genotype_api.exceptions import GenotypeDBError
4+
from genotype_api.database.database import close_session
55

66

77
class DBSessionMiddleware(BaseHTTPMiddleware):
@@ -11,11 +11,8 @@ def __init__(self, app):
1111
async def dispatch(self, request: Request, call_next):
1212
try:
1313
response = await call_next(request)
14-
except Exception as e:
15-
raise e
16-
finally:
17-
session = get_session()
18-
if session.is_active:
19-
session.rollback()
14+
except Exception:
15+
raise GenotypeDBError
16+
finally
2017
close_session()
2118
return response

0 commit comments

Comments
 (0)