fix(client): summarize HTML error bodies in API errors #13
fix/ci-job-view-html-errors
into main
Summary
When the server returns a non-2xx response with an HTML body (e.g. the 406 from the CI job-logs endpoint), every error path in `Client` was pasting the entire HTML page into `ApiError::Api.message`, producing an unreadable wall of markup in the user’s terminal.
Centralizes non-success handling into `api_error_from`, which inspects `Content-Type` and substitutes a short summary for `text/html` / `application/xhtml` bodies while leaving JSON/text bodies untouched.
Before
``` $ anvil ci job-view 7a1731da43 CI Job 7a1731da43 Name clippy … Error: API error (406):
After
``` $ anvil ci job-view 7a1731da43 CI Job 7a1731da43 Name clippy … Error: API error (406): server returned an HTML error page (expected JSON) ```
Test plan
- `cargo test` — 24 tests pass, including new `client::tests::*` covering happy + unhappy (JSON / HTML) paths for both `get` and `get_sse_stream`
- `cargo clippy –all-targets – -D warnings` clean
- `cargo fmt` clean
- Verified against production: `anvil ci job-view 7a1731da43` now prints the short message instead of an HTML page
Related
The server-side bugs (the 406 itself, and HTML-instead-of-JSON content negotiation) are tracked separately on `fangorn/anvil#205`.
Closes #7