{"record":{"id":"c64d86b964ae1610","repo":"mem0ai/mem0","slug":"net-generic","errorCode":"NET_GENERIC","errorMessage":"Network request failed: {str(e)}","messagePattern":"Network request failed: (.+?)","errorType":"exception","errorClass":"NetworkError","httpStatus":null,"severity":"error","filePath":"mem0/client/utils.py","lineNumber":86,"sourceCode":"def _handle_request_error(e):\n    logger.error(f\"Request error occurred: {e}\")\n\n    if isinstance(e, httpx.TimeoutException):\n        raise NetworkError(\n            message=f\"Request timed out: {str(e)}\",\n            error_code=\"NET_TIMEOUT\",\n            suggestion=\"Please check your internet connection and try again\",\n            debug_info={\"error_type\": \"timeout\", \"original_error\": str(e)},\n        )\n    elif isinstance(e, httpx.ConnectError):\n        raise NetworkError(\n            message=f\"Connection failed: {str(e)}\",\n            error_code=\"NET_CONNECT\",\n            suggestion=\"Please check your internet connection and try again\",\n            debug_info={\"error_type\": \"connection\", \"original_error\": str(e)},\n        )\n    else:\n        raise NetworkError(\n            message=f\"Network request failed: {str(e)}\",\n            error_code=\"NET_GENERIC\",\n            suggestion=\"Please check your internet connection and try again\",\n            debug_info={\"error_type\": \"request\", \"original_error\": str(e)},\n        )\n\n\ndef api_error_handler(func):\n    \"\"\"Decorator to handle API errors consistently.\n\n    This decorator catches HTTP and request errors and converts them to\n    appropriate structured exception classes with detailed error information.\n\n    Supports both sync and async functions.\n    \"\"\"\n    if inspect.iscoroutinefunction(func):\n        @wraps(func)\n        async def async_wrapper(*args, **kwargs):","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/client/utils.py#L68-L104","documentation":"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.","triggerScenarios":"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.","commonSituations":"Connection drops mid-response (mobile networks, pods being killed); malformed proxy responses; mismatched TLS interception middleboxes; response body truncation on unstable links.","solutions":["Inspect debug_info['original_error'] / the embedded string to identify the actual httpx failure class","Retry once or twice with backoff — many transport hiccups are transient","If a proxy or TLS middlebox is involved, test with it disabled to isolate the cause","Upgrade httpx/mem0ai if the underlying error is a known protocol bug"],"exampleFix":"# before\nresult = client.get_all(user_id=\"alice\")  # raises NET_GENERIC, unhandled\n\n# after\nfrom mem0.client.main import MemoryClient\ntry:\n    result = client.get_all(user_id=\"alice\")\nexcept NetworkError as e:\n    logger.warning(\"transport failure: %s (%s)\", e.message, e.debug_info.get(\"original_error\"))\n    result = retry_with_backoff(lambda: client.get_all(user_id=\"alice\"), attempts=3)","handlingStrategy":"retry","validationCode":null,"typeGuard":"def is_generic_network(err) -> bool:\n    return getattr(err, \"error_code\", None) == \"NET_GENERIC\"","tryCatchPattern":"try:\n    result = client.get_all(user_id=uid)\nexcept NetworkError as e:\n    if e.error_code == \"NET_GENERIC\":\n        cause = e.debug_info.get(\"original_error\", \"\")\n        logger.warning(\"transport error (%s); retrying once\", cause)\n        result = client.get_all(user_id=uid)  # single bounded retry\n    else:\n        raise","preventionTips":["Always inspect debug_info.original_error to classify the real httpx failure before choosing retry vs abort","Bound retries and surface the underlying cause in logs; NET_GENERIC is a family, not one failure"],"tags":["network","httpx","transport","hosted-api"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}