mirror of
https://github.com/olegvodyanov/docbot.git
synced 2025-12-19 23:57:05 +03:00
changes made by AI
This commit is contained in:
parent
70345f991d
commit
3d8044955c
4
src/core/exceptions.py
Normal file
4
src/core/exceptions.py
Normal file
@ -0,0 +1,4 @@
|
||||
class DatabaseError(Exception):
|
||||
"""Custom exception for database-related errors."""
|
||||
def __init__(self, message: str = "A database error occurred"):
|
||||
super().__init__(message)
|
||||
@ -22,6 +22,7 @@ from docbot.services.doctors_service import (
|
||||
)
|
||||
from docbot.services.session_service import create_session
|
||||
from core.logging import logger
|
||||
from core.exceptions import DatabaseError # Assuming a custom exception for database-related issues
|
||||
|
||||
|
||||
SEND_ACKNOWLEDGEMENT_INFO = 1
|
||||
@ -73,7 +74,14 @@ async def accept_personal_data_agreement(update: Update, context: ContextTypes.D
|
||||
user_data = context.user_data
|
||||
user_data['telegram_id'] = user_id = update.effective_user.id
|
||||
|
||||
registered = await get_patient_by_telegram_id(user_id)
|
||||
try:
|
||||
registered = await get_patient_by_telegram_id(user_id)
|
||||
except DatabaseError as e:
|
||||
logger.error(f"Database error while fetching patient by Telegram ID {user_id}: {e}")
|
||||
await update.message.reply_text(
|
||||
"❌ Произошла ошибка при обработке вашего запроса. Пожалуйста, попробуйте позже."
|
||||
)
|
||||
return ConversationHandler.END
|
||||
|
||||
logger.info(f"User {user_id} initiated consultation process.")
|
||||
logger.info(f"User exists? {registered}")
|
||||
@ -95,14 +103,21 @@ async def accept_personal_data_agreement(update: Update, context: ContextTypes.D
|
||||
|
||||
|
||||
async def receive_patient_aceptance(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
|
||||
logger.info(f"Next function receive_patient_aceptance")
|
||||
user_data = context.user_data
|
||||
await update.callback_query.answer()
|
||||
|
||||
if update.callback_query.data == "consult:accepted":
|
||||
user_data['accepted'] = True
|
||||
user_id = user_data['telegram_id']
|
||||
await create_patient(telegram_id=user_id, terms_acceptance=True) # Создаем пациента в БД
|
||||
try:
|
||||
await create_patient(telegram_id=user_id, terms_acceptance=True) # Создаем пациента в БД
|
||||
except DatabaseError as e:
|
||||
logger.error(f"Failed to create patient for user {user_id}: {e}")
|
||||
await update.callback_query.edit_message_text(
|
||||
text="❌ Произошла ошибка при создании вашей записи. Пожалуйста, попробуйте позже."
|
||||
)
|
||||
return ConversationHandler.END
|
||||
|
||||
await update.callback_query.edit_message_text(
|
||||
text="✅ Спасибо за подтверждение. Вы можете продолжить запись на консультацию.",
|
||||
parse_mode="Markdown",
|
||||
@ -279,16 +294,30 @@ async def receive_consultation_date(update: Update, context: ContextTypes.DEFAUL
|
||||
async def pay_consultation(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
|
||||
user_id = context.user_data['telegram_id']
|
||||
consultation_date_time = context.user_data['consultation_date_time']
|
||||
patient = await get_patient_by_telegram_id(user_id)
|
||||
doctor = await get_doctor_by_code(context.user_data['doctor_number'])
|
||||
try:
|
||||
patient = await get_patient_by_telegram_id(user_id)
|
||||
doctor = await get_doctor_by_code(context.user_data['doctor_number'])
|
||||
except DatabaseError as e:
|
||||
logger.error(f"Database error during payment process for user {user_id}: {e}")
|
||||
await update.callback_query.message.reply_text(
|
||||
"❌ Произошла ошибка при обработке вашего запроса. Пожалуйста, попробуйте позже."
|
||||
)
|
||||
return ConversationHandler.END
|
||||
|
||||
await create_session(
|
||||
telegram_id=user_id,
|
||||
phone=patient.phone,
|
||||
consultation_date_time=consultation_date_time,
|
||||
patient=patient,
|
||||
doctor_id=doctor.id if doctor else None
|
||||
)
|
||||
try:
|
||||
await create_session(
|
||||
telegram_id=user_id,
|
||||
phone=patient.phone,
|
||||
consultation_date_time=consultation_date_time,
|
||||
patient=patient,
|
||||
doctor_id=doctor.id if doctor else None
|
||||
)
|
||||
except DatabaseError as e:
|
||||
logger.error(f"Failed to create session for user {user_id}: {e}")
|
||||
await update.callback_query.message.reply_text(
|
||||
"❌ Произошла ошибка при создании записи на консультацию. Пожалуйста, попробуйте позже."
|
||||
)
|
||||
return ConversationHandler.END
|
||||
|
||||
link = await get_doctors_payment_link(context.user_data['doctor_number'])
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user