File size: 2,024 Bytes
d8441b6
 
a6e7bec
 
 
 
d8441b6
 
 
 
 
a6e7bec
 
 
 
 
d8441b6
 
 
 
 
 
 
 
a6e7bec
 
 
 
 
d8441b6
 
 
 
 
 
 
 
a6e7bec
 
 
 
 
d8441b6
 
 
 
 
 
 
 
a6e7bec
 
 
 
 
d8441b6
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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):

    @app.errorhandler(ValueError)
    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


    @app.errorhandler(FileNotFoundError)
    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


    @app.errorhandler(IOError)
    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


    @app.errorhandler(Exception)
    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