MCPcopy Create free account
hub / github.com/block/buzz / handle_response

Method handle_response

crates/buzz-cli/src/client.rs:398–426  ·  view source on GitHub ↗
(&self, resp: reqwest::Response)

Source from the content-addressed store, hash-verified

396 }
397
398 async fn handle_response(&self, resp: reqwest::Response) -> Result<String, CliError> {
399 if !resp.status().is_success() {
400 let status = resp.status().as_u16();
401 let body = resp.text().await.unwrap_or_default();
402 let message = serde_json::from_str::<serde_json::Value>(&body)
403 .ok()
404 .and_then(|v| {
405 v.get("error")
406 .or_else(|| v.get("message"))
407 .and_then(|m| m.as_str())
408 .map(|s| s.to_string())
409 })
410 .unwrap_or(body);
411 if status == 403 && std::env::var("BUZZ_AUTH_TAG").is_ok() {
412 let message = format!(
413 "{message} (BUZZ_AUTH_TAG is set — it may be stale or revoked; try unsetting it)"
414 );
415 return Err(CliError::Relay {
416 status,
417 body: message,
418 });
419 }
420 return Err(CliError::Relay {
421 status,
422 body: message,
423 });
424 }
425 Ok(resp.text().await?)
426 }
427}
428
429/// Normalize a relay URL: ws:// → http://, wss:// → https://, strip trailing slash.

Callers 3

query_multiMethod · 0.80
countMethod · 0.80
submit_eventMethod · 0.80

Calls 5

textMethod · 0.80
statusMethod · 0.45
okMethod · 0.45
getMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected