- Introduction of Partner Admin role in combination with 'Management Partner' type.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import traceback
|
||||
|
||||
import jinja2
|
||||
from flask import render_template, request, jsonify, redirect, current_app
|
||||
from flask import render_template, request, jsonify, redirect, current_app, flash
|
||||
from flask_login import current_user
|
||||
from common.utils.nginx_utils import prefixed_url_for
|
||||
|
||||
@@ -41,12 +43,46 @@ def key_error_handler(error):
|
||||
return render_template('error/generic.html', error_message="An unexpected error occurred"), 500
|
||||
|
||||
|
||||
def attribute_error_handler(error):
|
||||
"""Handle AttributeError exceptions.
|
||||
|
||||
Specifically catches SQLAlchemy relationship errors when string IDs
|
||||
are used instead of model instances.
|
||||
"""
|
||||
error_msg = str(error)
|
||||
current_app.logger.error(f"AttributeError: {error_msg}")
|
||||
current_app.logger.error(traceback.format_exc())
|
||||
|
||||
# Handle the SQLAlchemy relationship error specifically
|
||||
if "'str' object has no attribute '_sa_instance_state'" in error_msg:
|
||||
flash('Database relationship error. Please check your form inputs and try again.', 'error')
|
||||
return render_template('errors/500.html',
|
||||
error_type="Relationship Error",
|
||||
error_details="A string value was provided where a database object was expected."), 500
|
||||
|
||||
# Handle other AttributeErrors
|
||||
flash('An application error occurred. The technical team has been notified.', 'error')
|
||||
return render_template('errors/500.html',
|
||||
error_type="Attribute Error",
|
||||
error_details=error_msg), 500
|
||||
|
||||
|
||||
def general_exception(e):
|
||||
current_app.logger.error(f"Unhandled Exception: {e}", exc_info=True)
|
||||
flash('An application error occurred. The technical team has been notified.', 'error')
|
||||
return render_template('errors/500.html',
|
||||
error_type=type(e).__name__,
|
||||
error_details=str(e)), 500
|
||||
|
||||
|
||||
def register_error_handlers(app):
|
||||
app.register_error_handler(404, not_found_error)
|
||||
app.register_error_handler(500, internal_server_error)
|
||||
app.register_error_handler(401, not_authorised_error)
|
||||
app.register_error_handler(403, not_authorised_error)
|
||||
app.register_error_handler(KeyError, key_error_handler)
|
||||
app.register_error_handler(AttributeError, attribute_error_handler)
|
||||
app.register_error_handler(Exception, general_exception)
|
||||
|
||||
@app.errorhandler(jinja2.TemplateNotFound)
|
||||
def template_not_found(error):
|
||||
|
||||
Reference in New Issue
Block a user