From 7784738f3692f220a2444191efa819562f3b9315 Mon Sep 17 00:00:00 2001 From: ntner Date: Tue, 31 Mar 2026 15:19:06 -0400 Subject: [PATCH] add content type guard catch --- src/convox/_http.py | 12 ++++++++++++ src/convox/client.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/convox/_http.py b/src/convox/_http.py index a60671e..729b79e 100644 --- a/src/convox/_http.py +++ b/src/convox/_http.py @@ -237,6 +237,18 @@ def request( request_id = response.headers.get("request-id") raise exception_for_response(response.status_code, message, request_id) + # Guard against non-JSON success responses. The Convox console + # returns its HTML UI when no Rack header is present; without + # this check callers would get an opaque JSONDecodeError. + ct = response.headers.get("content-type", "") + if "text/html" in ct: + raise exception_for_response( + 502, + "Expected JSON response but received HTML. " + "If you are connecting through a Convox console, " + "make sure the 'rack' parameter is set.", + ) + return response def get(self, path: str, **kwargs: Any) -> httpx.Response: diff --git a/src/convox/client.py b/src/convox/client.py index 159996d..04fc640 100644 --- a/src/convox/client.py +++ b/src/convox/client.py @@ -110,7 +110,7 @@ def from_env( import os host, api_key = credentials_from_env() - rack = os.environ.get("CONVOX_RACK") + rack = os.environ.get("CONVOX_RACK") or None return cls(host, api_key, rack=rack, retry=retry, timeout=timeout) @classmethod