| 278 | } |
| 279 | |
| 280 | fn parse_error_body(&self, status: u16, body: &str) -> RemoteError { |
| 281 | // Try to parse as ApiResponse first. |
| 282 | if let Ok(api_resp) = serde_json::from_str::<ApiResponse<serde_json::Value>>(body) { |
| 283 | if let Some(err) = api_resp.error { |
| 284 | return self.status_error(status, err.message); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | // Some endpoints return a direct ApiError body instead of the |
| 289 | // ApiResponse envelope on validation/auth failures. |
| 290 | if let Ok(err) = serde_json::from_str::<crate::storage_types::ApiError>(body) { |
| 291 | return self.status_error(status, err.message); |
| 292 | } |
| 293 | |
| 294 | RemoteError::server_error(status, format!("HTTP {}", status)) |
| 295 | } |
| 296 | |
| 297 | fn status_error(&self, status: u16, message: String) -> RemoteError { |
| 298 | match status { |