Download middleware/error_handler.py from BhojGC/MyApp: direct link, hf CLI and curl.
- Browser
- Download file 2.02 kB
-
https://huggingface.co/spaces/BhojGC/MyApp/resolve/main/middleware/error_handler.py
- Command line
-
hf download hf://spaces/BhojGC/MyApp/middleware/error_handler.py
-
curl -L -o error_handler.py https://huggingface.co/spaces/BhojGC/MyApp/resolve/main/middleware/error_handler.py
2.02 kB
| from flask import jsonify | |
| from config.logger_config import configure_logging | |
| from app_constants.logging_enums import ApplicationLayerLogging, LogEvent, LoggingComponent | |
| logger = configure_logging() | |
| def register_error_handlers(app): | |
| def handle_value_error(error): | |
| logger.error("[%s] [%s] value error occurred: [%s] [%s]", | |
| ApplicationLayerLogging.MIDDLEWARE.value, | |
| LoggingComponent.GLOBAL_EXCEPTION.value, | |
| str(error), | |
| LogEvent.ERROR.value) | |
| return jsonify({ | |
| "success": False, | |
| "message": str(error) | |
| }), 400 | |
| def handle_file_error(error): | |
| logger.error("[%s] [%s] file not found error occurred: [%s] [%s]", | |
| ApplicationLayerLogging.MIDDLEWARE.value, | |
| LoggingComponent.GLOBAL_EXCEPTION.value, | |
| str(error), | |
| LogEvent.ERROR.value) | |
| return jsonify({ | |
| "success": False, | |
| "message": str(error) | |
| }), 404 | |
| def handle_io_error(error): | |
| logger.error("[%s] [%s] input output error occurred: [%s] [%s]", | |
| ApplicationLayerLogging.MIDDLEWARE.value, | |
| LoggingComponent.GLOBAL_EXCEPTION.value, | |
| str(error), | |
| LogEvent.ERROR.value) | |
| return jsonify({ | |
| "success": False, | |
| "message": str(error) | |
| }), 500 | |
| def handle_exception(error): | |
| logger.error("[%s] [%s] unknown exception occurred: [%s] [%s]", | |
| ApplicationLayerLogging.MIDDLEWARE.value, | |
| LoggingComponent.GLOBAL_EXCEPTION.value, | |
| str(error), | |
| LogEvent.ERROR.value) | |
| return jsonify({ | |
| "success": False, | |
| "message": str(error) | |
| }), 500 |