view_error_management.py 901 B

12345678910111213141516171819202122
  1. import View.view_privilege as privileges
  2. import logging
  3. from flask import jsonify
  4. from utility.app_logging import logger_name
  5. logger = logging.getLogger(logger_name + ".VIEW")
  6. import traceback
  7. def define_error_management(app) :
  8. @app.errorhandler(500)
  9. def handle_error(err) :
  10. """Return JSON instead of HTML for any other server error"""
  11. logger.error(f"Unknown Exception: {str(err)}")
  12. logger.debug(''.join(traceback.format_exception(etype=type(err), value=err, tb=err.__traceback__)))
  13. response = {"error": str(err) }
  14. return jsonify(response), 500
  15. @app.errorhandler(privileges.PrivilegeError)
  16. def handle_error(err) :
  17. """Return JSON instead of HTML for any other server error"""
  18. logger.error(f"APIAuthError Exception: {str(err)}")
  19. response = {"error": str(err) }
  20. return jsonify(response), 500