Uklid v alembic migracich, error logging, upravy kvuli autorizaci

This commit is contained in:
Michal Kváček
2023-08-14 15:01:13 +02:00
parent bc260a2a8b
commit 97295c17c0
38 changed files with 203 additions and 957 deletions
+14 -2
View File
@@ -1,7 +1,19 @@
from functools import wraps
from fastapi import HTTPException
from starlette.status import HTTP_401_UNAUTHORIZED
def public_endpoint(func):
pass
def private_endpoint(func):
pass
def authenticated_user_only(func):
@wraps(func)
async def decorator(*args, **kwargs):
if 'info' in kwargs:
if not kwargs['info'].context.user_id:
raise HTTPException(HTTP_401_UNAUTHORIZED, "Not authorized")
return await func(*args, **kwargs)
return decorator
+3 -2
View File
@@ -1,5 +1,6 @@
from functools import wraps
from graphql import GraphQLError
from sqlalchemy.exc import NoResultFound
def error_logging(func):
@@ -7,7 +8,7 @@ def error_logging(func):
async def decorator(*args, **kwargs):
try:
return await func(*args, **kwargs)
except Exception as e:
raise GraphQLError(f"Not found")
except NoResultFound as e:
raise GraphQLError(f"Not found", original_error=e)
return decorator