Files
tgex-backend/src/domain/error.py
Artem Tsyrulnikov c04faf8132 креативы
2026-01-03 16:11:05 +03:00

127 lines
5.0 KiB
Python

import uuid
from fastapi import HTTPException, status
def UserNotFound(user_id: uuid.UUID | None = None) -> HTTPException:
if user_id is None:
return HTTPException(status.HTTP_404_NOT_FOUND, 'User not found')
return HTTPException(status.HTTP_404_NOT_FOUND, f'User {user_id} not found')
def UserByUsernameNotFound(username: str) -> HTTPException:
return HTTPException(status.HTTP_404_NOT_FOUND, f'User @{username} not found')
def LoginTokenNotFound() -> HTTPException:
return HTTPException(status.HTTP_404_NOT_FOUND, 'Login token not found')
def LoginTokenExpired() -> HTTPException:
return HTTPException(status.HTTP_400_BAD_REQUEST, 'Login token has expired')
def LoginTokenAlreadyUsed() -> HTTPException:
return HTTPException(status.HTTP_400_BAD_REQUEST, 'Login token has already been used')
def ChannelNotFound(channel_id: uuid.UUID | None = None) -> HTTPException:
if channel_id is None:
return HTTPException(status.HTTP_404_NOT_FOUND, 'Channel not found')
return HTTPException(status.HTTP_404_NOT_FOUND, f'Channel {channel_id} not found')
def TelegramChannelNotFound(username: str) -> HTTPException:
return HTTPException(
status.HTTP_404_NOT_FOUND, f'Telegram channel @{username} not found or is not a public channel'
)
def ProjectNotFound(project_id: uuid.UUID | None = None) -> HTTPException:
if project_id is None:
return HTTPException(status.HTTP_404_NOT_FOUND, 'Project not found')
return HTTPException(status.HTTP_404_NOT_FOUND, f'Project {project_id} not found')
def PurchaseNotFound(purchase_id: uuid.UUID | None = None) -> HTTPException:
if purchase_id is None:
return HTTPException(status.HTTP_404_NOT_FOUND, 'Purchase not found')
return HTTPException(status.HTTP_404_NOT_FOUND, f'Purchase {purchase_id} not found')
def PurchaseChannelNotFound(purchase_channel_id: uuid.UUID | None = None) -> HTTPException:
if purchase_channel_id is None:
return HTTPException(status.HTTP_404_NOT_FOUND, 'Purchase channel not found')
return HTTPException(status.HTTP_404_NOT_FOUND, f'Purchase channel {purchase_channel_id} not found')
def ChannelAlreadyExists(telegram_id: int) -> HTTPException:
return HTTPException(status.HTTP_409_CONFLICT, f'Channel {telegram_id} already exists in the system')
def ChannelNoAdminRights() -> HTTPException:
return HTTPException(
status.HTTP_403_FORBIDDEN, 'Bot must be added as administrator with invite link creation rights'
)
def CreativeNotFound(creative_id: uuid.UUID | None = None) -> HTTPException:
if creative_id is None:
return HTTPException(status.HTTP_404_NOT_FOUND, 'Creative not found')
return HTTPException(status.HTTP_404_NOT_FOUND, f'Creative {creative_id} not found')
def CreativeInviteLinkNotFound() -> HTTPException:
return HTTPException(status.HTTP_400_BAD_REQUEST, 'Creative text must contain one invite link (t.me/+xxx)')
def CreativeMultipleInviteLinks() -> HTTPException:
return HTTPException(status.HTTP_400_BAD_REQUEST, 'Creative text must contain only one invite link')
def CreativeMediaTooLarge(max_bytes: int) -> HTTPException:
return HTTPException(status.HTTP_400_BAD_REQUEST, f'Creative media is too large (max {max_bytes} bytes)')
def CreativeInUse(creative_id: uuid.UUID) -> HTTPException:
return HTTPException(
status.HTTP_400_BAD_REQUEST,
f'Creative {creative_id} is used in active placements and cannot be deleted',
)
def PlacementNotFound(placement_id: uuid.UUID | None = None) -> HTTPException:
if placement_id is None:
return HTTPException(status.HTTP_404_NOT_FOUND, 'Placement not found')
return HTTPException(status.HTTP_404_NOT_FOUND, f'Placement {placement_id} not found')
def WorkspaceNotFound(workspace_id: uuid.UUID | None = None) -> HTTPException:
if workspace_id is None:
return HTTPException(status.HTTP_404_NOT_FOUND, 'Workspace not found')
return HTTPException(status.HTTP_404_NOT_FOUND, f'Workspace {workspace_id} not found')
def WorkspaceAccessDenied(workspace_id: uuid.UUID | None = None) -> HTTPException:
if workspace_id is None:
return HTTPException(status.HTTP_403_FORBIDDEN, 'Workspace access denied')
return HTTPException(status.HTTP_403_FORBIDDEN, f'Workspace {workspace_id} access denied')
def WorkspaceInviteNotFound(invite_id: uuid.UUID | None = None) -> HTTPException:
if invite_id is None:
return HTTPException(status.HTTP_404_NOT_FOUND, 'Workspace invite not found')
return HTTPException(status.HTTP_404_NOT_FOUND, f'Workspace invite {invite_id} not found')
def WorkspaceInviteAlreadyExists() -> HTTPException:
return HTTPException(status.HTTP_409_CONFLICT, 'Workspace invite already exists for this user')
def WorkspaceInviteAlreadyProcessed() -> HTTPException:
return HTTPException(status.HTTP_400_BAD_REQUEST, 'Workspace invite has already been processed')
def WorkspaceMemberAlreadyExists() -> HTTPException:
return HTTPException(status.HTTP_409_CONFLICT, 'User is already a workspace member')