File size: 408 Bytes
8397f09
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import functools
from flask import jsonify
import logging

def handle_errors(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception as e:
            logging.exception(f"Unhandled exception in {func.__name__}")
            return jsonify({"success": False, "error": "Internal server error"}), 500
    return wrapper