| 246 | } |
| 247 | |
| 248 | fn parse_error_body(&self, status: u16, body: &str) -> RemoteError { |
| 249 | // Try to parse as ApiResponse first. |
| 250 | if let Ok(api_resp) = serde_json::from_str::<ApiResponse<serde_json::Value>>(body) { |
| 251 | if let Some(err) = api_resp.error { |
| 252 | return self.status_error(status, err.message); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | // Some endpoints return a direct ApiError body instead of the |
| 257 | // ApiResponse envelope on validation/auth failures. |
| 258 | if let Ok(err) = serde_json::from_str::<crate::storage_types::ApiError>(body) { |
| 259 | return self.status_error(status, err.message); |
| 260 | } |
| 261 | |
| 262 | RemoteError::server_error(status, format!("HTTP {}", status)) |
| 263 | } |
| 264 | |
| 265 | fn status_error(&self, status: u16, message: String) -> RemoteError { |
| 266 | match status { |