Make error messages more descriptive

- Added specific slot time and date to availability error message
- Added appointment ID and context to 'not found' errors
- Added formatted appointment time to past appointment cancellation errors
- Added date context to slot overlap error messages
- All errors now provide actionable information to users
This commit is contained in:
counterweight 2025-12-21 17:59:08 +01:00
parent 4d5673f181
commit 131477b7f3
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -194,7 +194,7 @@ async def create_booking(
if not matching_availability:
raise HTTPException(
status_code=400,
detail="Selected slot is not within available time ranges",
detail=f"Selected slot at {request.slot_start.strftime('%Y-%m-%d %H:%M')} UTC is not within any available time ranges for {slot_date}. Please select a different time slot.",
)
# Create the appointment
@ -264,7 +264,10 @@ async def cancel_my_appointment(
appointment = result.scalar_one_or_none()
if not appointment:
raise HTTPException(status_code=404, detail="Appointment not found")
raise HTTPException(
status_code=404,
detail=f"Appointment with ID {appointment_id} not found. It may have been deleted or the ID is invalid.",
)
# Verify ownership
if appointment.user_id != current_user.id:
@ -279,9 +282,10 @@ async def cancel_my_appointment(
# Check if appointment is in the past
if appointment.slot_start <= datetime.now(timezone.utc):
appointment_time = appointment.slot_start.strftime('%Y-%m-%d %H:%M') + " UTC"
raise HTTPException(
status_code=400,
detail="Cannot cancel a past appointment"
detail=f"Cannot cancel appointment scheduled for {appointment_time} as it is in the past or has already started."
)
# Cancel the appointment
@ -356,7 +360,10 @@ async def admin_cancel_appointment(
appointment = result.scalar_one_or_none()
if not appointment:
raise HTTPException(status_code=404, detail="Appointment not found")
raise HTTPException(
status_code=404,
detail=f"Appointment with ID {appointment_id} not found. It may have been deleted or the ID is invalid.",
)
# Check if already cancelled
if appointment.status != AppointmentStatus.BOOKED:
@ -367,9 +374,10 @@ async def admin_cancel_appointment(
# Check if appointment is in the past
if appointment.slot_start <= datetime.now(timezone.utc):
appointment_time = appointment.slot_start.strftime('%Y-%m-%d %H:%M') + " UTC"
raise HTTPException(
status_code=400,
detail="Cannot cancel a past appointment"
detail=f"Cannot cancel appointment scheduled for {appointment_time} as it is in the past or has already started."
)
# Cancel the appointment