cli: surface HTTP status and body on backend errors
This commit is contained in:
@@ -59,6 +59,11 @@ def save_response(response: httpx.Response, destination: Path) -> None:
|
||||
destination.write_bytes(response.content)
|
||||
|
||||
|
||||
def format_http_error(response: httpx.Response, endpoint: str) -> str:
|
||||
body = response.text.strip() or "<empty response body>"
|
||||
return f"HTTP {response.status_code} from {endpoint}: {body}"
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = build_parser()
|
||||
args = parser.parse_args()
|
||||
@@ -84,7 +89,7 @@ def main() -> int:
|
||||
try:
|
||||
response.raise_for_status()
|
||||
except httpx.HTTPStatusError as exc:
|
||||
message = exc.response.text.strip() or str(exc)
|
||||
message = format_http_error(exc.response, endpoint)
|
||||
parser.exit(1, f"{message}\n")
|
||||
|
||||
if args.to_file:
|
||||
|
||||
Reference in New Issue
Block a user