From a725ab392808f308353a32ac0a8d0cd441ff8c07 Mon Sep 17 00:00:00 2001 From: Mathias Rothenhaeusler Date: Wed, 21 Jan 2026 08:53:48 +0100 Subject: [PATCH] error message parsing problems --- src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 29a897b..6191d54 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,11 +2,11 @@ mod engine; use crate::engine::params::Params; use crate::engine::response::DeeplResponse; -use hyper::{body, Body, Client, Method, Request}; +use anyhow::{Context, Result}; +use hyper::{Body, Client, Method, Request, body}; use hyper_tls::HttpsConnector; -use anyhow::Result; -#[tokio::main(flavor = "current_thread")] +#[tokio::main(flavor = "current_thread")] async fn main() -> Result<()> { let https = HttpsConnector::new(); let client = Client::builder().build::<_, hyper::Body>(https); @@ -22,7 +22,8 @@ async fn main() -> Result<()> { let res = client.request(request).await?; let body_bytes = body::to_bytes(res.into_body()).await?; let body = String::from_utf8(body_bytes.to_vec())?; - let v: DeeplResponse = serde_json::from_str(&body)?; + let v: DeeplResponse = + serde_json::from_str(&body).context(format!("Could not parse body: {}", body))?; println!("{}", v.get_text(¶ms.target_lang)); Ok(()) }