(status: u16, bytes: &Bytes)
| 723 | // ── Helpers ────────────────────────────────────────────────────────────── |
| 724 | |
| 725 | fn error_from_response(status: u16, bytes: &Bytes) -> PodmanApiError { |
| 726 | let message = serde_json::from_slice::<Value>(bytes) |
| 727 | .ok() |
| 728 | .and_then(|v| { |
| 729 | v.get("message") |
| 730 | .or_else(|| v.get("cause")) |
| 731 | .and_then(Value::as_str) |
| 732 | .map(String::from) |
| 733 | }) |
| 734 | .unwrap_or_else(|| String::from_utf8_lossy(bytes).to_string()); |
| 735 | |
| 736 | match status { |
| 737 | 404 => PodmanApiError::NotFound(message), |
| 738 | 409 => PodmanApiError::Conflict(message), |
| 739 | _ => PodmanApiError::Api { status, message }, |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | /// Minimal percent-encoding for query parameter values. |
| 744 | /// |
no test coverage detected