- error handling now uses a more comprehensive error communication system.
This commit is contained in:
@@ -1,18 +1,20 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
from flask import Flask, jsonify, request, url_for
|
||||
from flask import Flask, jsonify, request, url_for, session as flask_session
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
import logging.config
|
||||
from jinja2 import ChoiceLoader, FileSystemLoader
|
||||
|
||||
from common.extensions import (db, bootstrap, cors, csrf, session,
|
||||
minio_client, simple_encryption, metrics, cache_manager, content_manager)
|
||||
from common.models.user import Tenant, SpecialistMagicLinkTenant
|
||||
from config.logging_config import configure_logging
|
||||
from eveai_chat_client.utils.errors import register_error_handlers
|
||||
from common.utils.errors import register_error_handlers
|
||||
from common.utils.celery_utils import make_celery, init_celery
|
||||
from common.utils.template_filters import register_filters
|
||||
from config.config import get_config
|
||||
from common.utils.chat_utils import get_default_chat_customisation
|
||||
|
||||
|
||||
def create_app(config_file=None):
|
||||
@@ -57,11 +59,23 @@ def create_app(config_file=None):
|
||||
app.celery = make_celery(app.name, app.config)
|
||||
init_celery(app.celery, app)
|
||||
|
||||
# Configure template loader with fallback to common/templates
|
||||
try:
|
||||
import os as _os
|
||||
common_templates_path = _os.path.normpath(_os.path.join(app.root_path, '..', 'common', 'templates'))
|
||||
app.jinja_loader = ChoiceLoader([
|
||||
app.jinja_loader,
|
||||
FileSystemLoader(common_templates_path),
|
||||
])
|
||||
app.logger.debug(f"Added common templates path: {common_templates_path}")
|
||||
except Exception as e:
|
||||
app.logger.error(f"Failed to configure ChoiceLoader for common templates: {e}")
|
||||
|
||||
# Register Blueprints
|
||||
register_blueprints(app)
|
||||
|
||||
# Register Error Handlers
|
||||
register_error_handlers(app)
|
||||
# Register Error Handlers (shared, profile-aware)
|
||||
register_error_handlers(app, profile='chat_client')
|
||||
|
||||
# Register Cache Handlers
|
||||
register_cache_handlers(app)
|
||||
@@ -85,6 +99,19 @@ def create_app(config_file=None):
|
||||
# Register template filters
|
||||
register_filters(app)
|
||||
|
||||
# Always inject chat customisation for templates (safe defaults)
|
||||
@app.context_processor
|
||||
def inject_customisation():
|
||||
try:
|
||||
tm = flask_session.get('tenant_make')
|
||||
options = None
|
||||
if tm and isinstance(tm, dict):
|
||||
options = tm.get('chat_customisation_options')
|
||||
customisation = get_default_chat_customisation(options)
|
||||
except Exception:
|
||||
customisation = get_default_chat_customisation(None)
|
||||
return {'customisation': customisation}
|
||||
|
||||
app.logger.info(f"EveAI Chat Client Started Successfully (PID: {os.getpid()})")
|
||||
app.logger.info("-------------------------------------------------------------------------------------------------")
|
||||
|
||||
@@ -115,8 +142,7 @@ def register_extensions(app):
|
||||
def register_blueprints(app):
|
||||
from .views.chat_views import chat_bp
|
||||
app.register_blueprint(chat_bp)
|
||||
from .views.error_views import error_bp
|
||||
app.register_blueprint(error_bp)
|
||||
# Do not register local error blueprint; use shared error handlers from common
|
||||
from .views.healthz_views import healthz_bp
|
||||
app.register_blueprint(healthz_bp)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user