Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/convox/_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/convox/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading