| 219 | } |
| 220 | |
| 221 | fn parse_error_body(&self, status: u16, body: &str) -> RemoteError { |
| 222 | // Try to parse as ApiResponse first. |
| 223 | if let Ok(api_resp) = serde_json::from_str::<ApiResponse<serde_json::Value>>(body) { |
| 224 | if let Some(err) = api_resp.error { |
| 225 | return self.status_error(status, err.message); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | // Some endpoints return a direct ApiError body instead of the |
| 230 | // ApiResponse envelope on validation/auth failures. |
| 231 | if let Ok(err) = serde_json::from_str::<crate::storage_types::ApiError>(body) { |
| 232 | return self.status_error(status, err.message); |
| 233 | } |
| 234 | |
| 235 | RemoteError::server_error(status, format!("HTTP {}", status)) |
| 236 | } |
| 237 | |
| 238 | fn status_error(&self, status: u16, message: String) -> RemoteError { |
| 239 | match status { |