Abstraction for Project in MemoryClient (#3067)

This commit is contained in:
Dev Khant
2025-07-08 11:33:20 +05:30
committed by GitHub
parent aae5989e78
commit 70d6f9231b
11 changed files with 1071 additions and 39 deletions

26
mem0/client/utils.py Normal file
View File

@@ -0,0 +1,26 @@
import httpx
import logging
logger = logging.getLogger(__name__)
class APIError(Exception):
"""Exception raised for errors in the API."""
pass
def api_error_handler(func):
"""Decorator to handle API errors consistently."""
from functools import wraps
@wraps(func)
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except httpx.HTTPStatusError as e:
logger.error(f"HTTP error occurred: {e}")
raise APIError(f"API request failed: {e.response.text}")
except httpx.RequestError as e:
logger.error(f"Request error occurred: {e}")
raise APIError(f"Request failed: {str(e)}")
return wrapper