Uklid v alembic migracich, error logging, upravy kvuli autorizaci
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user