@@ -19,6 +19,7 @@ from ninja.errors import HttpError from authentication.models import CustomUserModel from authentication.security import AsyncAuthBearer, SyncAuthBearer from payments.exceptions.payer_not_found import PayerNotFound +from authentication.exceptions.business_host_exceptions.access_denied import AccessDenied from payments.models import ( Invoice, Payment, @@ -161,7 +162,7 @@ def list_expenses(request, data: ExpensesParamsSchema = Query(...)): async def list_payment_plans(request): try: if request.auth.account_type not in {'regular', 'business_host'}: - raise HttpError(401, 'Unauthorized') + raise AccessDenied is_corporate = request.auth.account_type == 'business_host' plans = PaymentPlan.objects.filter( price__gt=0, is_corporate=is_corporate, is_visible=True @@ -199,6 +200,8 @@ async def list_payment_plans(request): ) ) return result + except AccessDenied as exc: + raise HttpError(403, str(exc)) except Exception as exc: logger.exception(exc, exc_info=True) raise HttpError(400, f'{exc}') @@ -208,7 +211,7 @@ async def list_payment_plans(request): async def create_payment_link(request, body: NewSubscriptionSchema): try: if request.auth.account_type not in {'regular', 'business_host'}: - raise HttpError(401, 'Unauthorized') + raise AccessDenied is_corporate = request.auth.account_type == 'business_host' payment_plan = await PaymentPlan.objects.aget( uid=body.uid, price__gt=0, is_corporate=is_corporate, is_visible=True, individual=False @@ -220,6 +223,8 @@ async def create_payment_link(request, body: NewSubscriptionSchema): payment_plan.uid, ) return PaymentLinkSchema(payment_url=payment_url) + except AccessDenied as exc: + raise HttpError(403, str(exc)) except Exception as exc: raise HttpError(400, f'{exc}')