""" This module contains decorators to handle exceptions in endpoint functions. """ from functools import wraps from .connectors import youtube_apis from .constants import ErrorMessages from .responses import json_404 def handle_exceptions(func): """Decorator to handle exceptions in a FastAPI endpoint function.""" @wraps(func) async def wrapper(*args, **kwargs): try: return await func(*args, **kwargs) # Define below exceptions to be handled. Any other exceptions will be # raised as they are. except youtube_apis.exceptions.NotFound: return json_404(error=ErrorMessages.YOUTUBE_NOT_FOUND) return wrapper