{"record":{"id":"5287b2ff6d49b998","repo":"calesthio/OpenMontage","slug":"atlas-cloud-returned-a-non-json-response-text-5","errorCode":null,"errorMessage":"Atlas Cloud returned a non-JSON response: {text[:500]}","messagePattern":"Atlas Cloud returned a non-JSON response: (.+?)","errorType":"exception","errorClass":"AtlasError","httpStatus":null,"severity":"error","filePath":"tools/atlas_client.py","lineNumber":79,"sourceCode":"\ndef _headers(api_key: str, json_body: bool = True) -> dict[str, str]:\n    headers = {\"Authorization\": f\"Bearer {api_key}\"}\n    if json_body:\n        headers[\"Content-Type\"] = \"application/json\"\n    return headers\n\n\ndef _payload_of(response: Any) -> dict[str, Any]:\n    \"\"\"Parse an Atlas envelope, raising AtlasError with the body on any problem.\n\n    Atlas wraps results as {\"code\": 200, \"data\": {...}}. A non-200 `code` can ride\n    along with HTTP 200, so the envelope is checked even on a successful request.\n    \"\"\"\n    try:\n        body = response.json()\n    except Exception as exc:  # noqa: BLE001 - surface the raw text, not a parse trace\n        text = getattr(response, \"text\", \"\")\n        raise AtlasError(f\"Atlas Cloud returned a non-JSON response: {text[:500]}\") from exc\n\n    if not isinstance(body, dict):\n        raise AtlasError(f\"Atlas Cloud returned an unexpected payload: {str(body)[:500]}\")\n\n    code = body.get(\"code\")\n    if code is not None and int(code) != 200:\n        message = body.get(\"message\") or body.get(\"error\") or str(body)[:500]\n        raise AtlasError(f\"Atlas Cloud error (code {code}): {message}\")\n\n    data = body.get(\"data\")\n    if data is None:\n        # uploadMedia historically answered with a bare {\"url\": ...}.\n        return body\n    if not isinstance(data, dict):\n        raise AtlasError(f\"Atlas Cloud returned an unexpected 'data' field: {str(data)[:500]}\")\n    return data\n\n","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/atlas_client.py#L61-L97","documentation":"Raised by _payload_of when response.json() fails while parsing an Atlas Cloud response, meaning the server returned a body that is not valid JSON (typically HTML or empty). The first 500 characters of the raw body are included to expose what actually came back. This guards every Atlas call: submit, poll, and upload_media all route through _payload_of.","triggerScenarios":"Any submit/poll/upload request whose response is an HTML error page from a gateway (502/503), a WAF challenge, or an empty body from a dropped connection; DNS pointing at the wrong host serving a landing page.","commonSituations":"Atlas Cloud transient gateway outages; corporate proxies injecting HTML; wrong ATLASCLOUD base endpoint URL from a stale env var; response bodies truncated by intermediary timeouts.","solutions":["Inspect the included body snippet — HTML title usually names the culprit (proxy, WAF, outage page)","Retry after a short delay; transient gateway HTML responses typically resolve","If persistent, verify the Atlas endpoint URL and network path (proxy bypass) for the API host","Check Atlas Cloud status page for incidents"],"exampleFix":"// before\npred_id = atlas_client.submit(endpoint, payload, api_key)\n\n// after — retry transient parse failures\nfor attempt in range(3):\n    try:\n        pred_id = atlas_client.submit(endpoint, payload, api_key)\n        break\n    except AtlasError as e:\n        if \"non-JSON\" not in str(e) or attempt == 2:\n            raise\n        time.sleep(5 * (attempt + 1))","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    data = atlas_client.submit(endpoint, payload, api_key)\nexcept AtlasError as e:\n    if \"non-JSON\" not in str(e):\n        raise\n    time.sleep(5)\n    data = atlas_client.submit(endpoint, payload, api_key)  # single retry","preventionTips":["Read the included 500-char body snippet before assuming a client bug","Monitor the Atlas status page during incident windows","Bypass HTML-injecting proxies for the Atlas host"],"tags":["atlas-cloud","json","http","network","gateway"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}