mem0ai/mem0 · error · NetworkError

NET_GENERIC

NET_GENERIC

Error message

Network request failed: {str(e)}

What it means

The catch-all branch of _handle_request_error: any httpx request exception that is neither a TimeoutException nor a ConnectError becomes NetworkError with code NET_GENERIC. This covers protocol errors, TLS errors mid-request, and other transport failures. The original exception text is preserved in message and debug_info.

Source

Thrown at mem0/client/utils.py:86

def _handle_request_error(e):
    logger.error(f"Request error occurred: {e}")

    if isinstance(e, httpx.TimeoutException):
        raise NetworkError(
            message=f"Request timed out: {str(e)}",
            error_code="NET_TIMEOUT",
            suggestion="Please check your internet connection and try again",
            debug_info={"error_type": "timeout", "original_error": str(e)},
        )
    elif isinstance(e, httpx.ConnectError):
        raise NetworkError(
            message=f"Connection failed: {str(e)}",
            error_code="NET_CONNECT",
            suggestion="Please check your internet connection and try again",
            debug_info={"error_type": "connection", "original_error": str(e)},
        )
    else:
        raise NetworkError(
            message=f"Network request failed: {str(e)}",
            error_code="NET_GENERIC",
            suggestion="Please check your internet connection and try again",
            debug_info={"error_type": "request", "original_error": str(e)},
        )


def api_error_handler(func):
    """Decorator to handle API errors consistently.

    This decorator catches HTTP and request errors and converts them to
    appropriate structured exception classes with detailed error information.

    Supports both sync and async functions.
    """
    if inspect.iscoroutinefunction(func):
        @wraps(func)
        async def async_wrapper(*args, **kwargs):

View on GitHub (pinned to 001c235229)

Solutions

  1. Inspect debug_info['original_error'] / the embedded string to identify the actual httpx failure class
  2. Retry once or twice with backoff — many transport hiccups are transient
  3. If a proxy or TLS middlebox is involved, test with it disabled to isolate the cause
  4. Upgrade httpx/mem0ai if the underlying error is a known protocol bug

Example fix

# before
result = client.get_all(user_id="alice")  # raises NET_GENERIC, unhandled

# after
from mem0.client.main import MemoryClient
try:
    result = client.get_all(user_id="alice")
except NetworkError as e:
    logger.warning("transport failure: %s (%s)", e.message, e.debug_info.get("original_error"))
    result = retry_with_backoff(lambda: client.get_all(user_id="alice"), attempts=3)
Defensive patterns

Strategy: retry

Type guard

def is_generic_network(err) -> bool:
    return getattr(err, "error_code", None) == "NET_GENERIC"

Try / catch

try:
    result = client.get_all(user_id=uid)
except NetworkError as e:
    if e.error_code == "NET_GENERIC":
        cause = e.debug_info.get("original_error", "")
        logger.warning("transport error (%s); retrying once", cause)
        result = client.get_all(user_id=uid)  # single bounded retry
    else:
        raise

Prevention

When it happens

Trigger: Any decorated API call raising e.g. httpx.RemoteProtocolError, httpx.ReadError, httpx.TooManyRedirects, httpx.DecodingError, or httpx.InvalidURL during the request — anything outside the timeout/connect branches.

Common situations: Connection drops mid-response (mobile networks, pods being killed); malformed proxy responses; mismatched TLS interception middleboxes; response body truncation on unstable links.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/c64d86b964ae1610. Report an issue: GitHub.