view_error_management.py 1003 B

1234567891011121314151617181920212223
  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.APIAuthError)
  16. def handle_error(err) :
  17. """Return JSON instead of HTML for any other server error"""
  18. logger.error(f"Unknown Exception: {str(err)}")
  19. logger.debug(''.join(traceback.format_exception(etype=type(err), value=err, tb=err.__traceback__)))
  20. response = {"error": str(err) }
  21. return jsonify(response), 500