(&self, op: &'static str, body: &Req)
| 259 | } |
| 260 | |
| 261 | async fn post_unit<Req>(&self, op: &'static str, body: &Req) -> Result<()> |
| 262 | where |
| 263 | Req: Serialize + ?Sized, |
| 264 | { |
| 265 | let url = self.endpoint(op); |
| 266 | let mut req = self.http.post(&url).json(body); |
| 267 | if let Some(token) = self.bearer_token.as_deref() { |
| 268 | if !token.is_empty() { |
| 269 | req = req.bearer_auth(token); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | let start = std::time::Instant::now(); |
| 274 | let send_result = req.send().await; |
| 275 | let status_code = send_result.as_ref().ok().map(|r| r.status().as_u16()); |
| 276 | let ok = matches!(send_result.as_ref(), Ok(r) if r.status().is_success()); |
| 277 | emit_remote_git_event(op, &self.repo_id, status_code, ok, start.elapsed(), None); |
| 278 | |
| 279 | let resp = |
| 280 | send_result.map_err(|e| anyhow!("remote git call '{}' transport error: {}", op, e))?; |
| 281 | |
| 282 | let status = resp.status(); |
| 283 | if status.is_success() { |
| 284 | return Ok(()); |
| 285 | } |
| 286 | let body_text = resp.text().await.unwrap_or_default(); |
| 287 | Err(map_error_response(op, status, &body_text)) |
| 288 | } |
| 289 | |
| 290 | /// Like [`Self::post_json`] but with a hard cap on the streamed response |
| 291 | /// body in bytes, intended for endpoints that can legitimately return |
no test coverage detected