- error handling now uses a more comprehensive error communication system.

This commit is contained in:
Josako
2025-09-11 14:46:28 +02:00
parent 7cb19ca21e
commit a325fa5084
13 changed files with 216 additions and 59 deletions

View File

@@ -37,9 +37,7 @@ def log_after_request(response):
@chat_bp.route('/')
def index():
customisation = get_default_chat_customisation()
return render_template('error.html', message="Please use a valid magic link to access the chat.",
customisation=customisation)
return render_template('error/404.html'), 404
@chat_bp.route('/<magic_link_code>')
@@ -53,14 +51,14 @@ def chat(magic_link_code):
if not magic_link_tenant:
current_app.logger.error(f"Invalid magic link code: {magic_link_code}")
return render_template('error.html', message="Invalid magic link code.")
return render_template('error/404.html'), 404
# Get tenant information
tenant_id = magic_link_tenant.tenant_id
tenant = Tenant.query.get(tenant_id)
if not tenant:
current_app.logger.error(f"Tenant not found for ID: {tenant_id}")
return render_template('error.html', message="Tenant not found.")
return render_template('error/404.html'), 404
# Switch to tenant schema
Database(tenant_id).switch_schema()
@@ -68,19 +66,19 @@ def chat(magic_link_code):
specialist_ml = SpecialistMagicLink.query.filter_by(magic_link_code=magic_link_code).first()
if not specialist_ml:
current_app.logger.error(f"Specialist magic link not found in tenant schema: {tenant_id}")
return render_template('error.html', message="Specialist configuration not found.")
return render_template('error/404.html'), 404
# Get relevant TenantMake
tenant_make = TenantMake.query.get(specialist_ml.tenant_make_id)
if not tenant_make:
current_app.logger.error(f"Tenant make not found: {specialist_ml.tenant_make_id}")
return render_template('error.html', message="Tenant make not found.")
return render_template('error/500.html'), 500
# Get specialist details
specialist = Specialist.query.get(specialist_ml.specialist_id)
if not specialist:
current_app.logger.error(f"Specialist not found: {specialist_ml.specialist_id}")
return render_template('error.html', message="Specialist not found.")
return render_template('error/404.html'), 404
# Store necessary information in session
session['tenant'] = tenant.to_dict()
@@ -124,7 +122,7 @@ def chat(magic_link_code):
except Exception as e:
current_app.logger.error(f"Error in chat view: {str(e)}", exc_info=True)
return render_template('error.html', message="An error occurred while setting up the chat.")
return render_template('error/500.html'), 500
@chat_bp.route('/api/send_message', methods=['POST'])