21 lines
		
	
	
		
			614 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			21 lines
		
	
	
		
			614 B
		
	
	
	
		
			Python
		
	
	
	
	
	
from functools import wraps
 | 
						|
from codes.common import db_operation
 | 
						|
from inspect import getfile
 | 
						|
from pathlib import Path
 | 
						|
 | 
						|
 | 
						|
def handle_exception(stop: bool = False):
 | 
						|
    def exceptions(func):
 | 
						|
        module = Path(getfile(func)).stem
 | 
						|
        func_name = func.__name__
 | 
						|
        @wraps(func)
 | 
						|
        def wrapper(*args, **kwargs):
 | 
						|
            try:
 | 
						|
                return func(*args, **kwargs)
 | 
						|
            except Exception as e:
 | 
						|
                db_operation.db_write_logs(str(e), "@".join([func_name, module]), "exception")
 | 
						|
                if stop:
 | 
						|
                    raise e
 | 
						|
        return wrapper
 | 
						|
    return exceptions
 |