apix/services/crawl4ai/app/grok/runtime.py
Khoa.vo 2a4bf8b58b
Some checks are pending
CI / build (18.x) (push) Waiting to run
CI / build (20.x) (push) Waiting to run
feat: updates before deployment
2026-01-06 13:26:11 +07:00

49 lines
No EOL
1.2 KiB
Python

from typing import Callable, Any, Optional, Type
from functools import wraps
from .logger import Log
class Run:
"""
Class to handle runtime
"""
@staticmethod
def Error(func: Callable[..., Any]) -> Callable[..., Any]:
"""
Error function to catch errors
@param func: The function to wrap.
@return: Custom error message
"""
@wraps(func)
def wrapper(*args: Any, **kwargs: Any) -> Any:
try:
return func(*args, **kwargs)
except Exception as e:
Run.handle_error(e)
return None
return wrapper
@staticmethod
def handle_error(exception: Exception) -> Optional[None]:
"""
Handling an error
@param exception: Exception that occured
"""
Log.Error(f"Error occurred: {exception}")
exit()
class Utils:
@staticmethod
def between(
main_text: Optional[str],
value_1: Optional[str],
value_2: Optional[str],
) -> str:
try:
return main_text.split(value_1)[1].split(value_2)[0]
except (IndexError, AttributeError):
return ""