ci job-view: surface HTML error pages as a short message instead of dumping raw HTML #7
closed
Opened by cole.christensen@gmail.com
Links
No links yet.
Problem
`anvil ci job-view ` against a completed job currently fails with the entire HTML error page pasted into the error string:
``` $ anvil ci job-view 7a1731da43 CI Job 7a1731da43 Name clippy Status passed …
Error: API error (406):
The server is returning a 406 with an HTML body. The CLI dumps the body verbatim because `Client::get_sse_stream` (and friends) just stuff `resp.text()` into `ApiError::Api.message` regardless of `Content-Type`.
There is a parallel server-side bug (the 406 itself, and HTML-instead-of-JSON content negotiation) — that is tracked separately on `fangorn/anvil`. This ticket is the CLI half.
Acceptance criteria
- When the API returns a non-2xx response with `Content-Type: text/html`, the CLI’s `ApiError::Api.message` contains a short, human-readable message — not the raw HTML body. Format: `server returned (HTML response from )`.
- When the API returns a non-2xx response with JSON, behavior is unchanged (we still surface the JSON body).
- Unit tests cover happy and unhappy paths for the response-handling helpers in `src/client.rs`:
- happy: 2xx JSON parses into the expected type
- unhappy: non-2xx with JSON body → `ApiError::Api` containing the JSON string
- unhappy: non-2xx with HTML body → `ApiError::Api` with a short summary, NOT the HTML
- unhappy: SSE stream variant of the same
- Tests run via `cargo test` and pass in CI.
Scope notes
- Touch `get_sse_stream`, `handle_response`, `get_raw`, `delete_empty`, `post_empty`, `upload_file`, `download_file` — anywhere we currently take `resp.text()` straight into `ApiError`.
- No new dependencies if avoidable; `wiremock` or `mockito` is acceptable as a dev-dependency for the tests.