123456789101112131415161718192021222324252627282930313233343536 |
- import View.view_privilege as privileges
- import logging
- from flask import Flask, jsonify
- from utility.app_logging import logger_name
- import sys
- logger = logging.getLogger(logger_name + ".VIEW")
- import traceback
- def define_error_management(app) :
- @app.errorhandler(500)
- def handle_error(err) :
- """Return JSON instead of HTML for any other server error"""
- logger.error(f"Unknown Exception: {str(err)}")
- logger.debug(''.join(traceback.format_exception(etype=type(err), value=err, tb=err.__traceback__)))
- response = {"error": str(err) }
- return jsonify(response), 500
- @app.errorhandler(privileges.PrivilegeError)
- def handle_privilege_error(err) :
- """Return JSON instead of HTML for any other server error"""
- logger.error(f"PrivilegeError Exception: {str(err)}")
- response = {"authorization error ": str(err) }
- return jsonify(response), 500
- @app.errorhandler(Exception)
- def handle_generic_error(err) :
- exc_type,exc_obj,exc_tb = sys.exc_info()
- """Return JSON instead of HTML for any other server error"""
- logger.error(f"Exception: {str(err) + traceback.format_exc()}")
- response = {"error": str(err) }
- return jsonify(response), 500
|