error message parsing problems

master
Mathias Rothenhaeusler 2026-01-21 08:53:48 +01:00
parent 498c963c20
commit a725ab3928
1 changed files with 5 additions and 4 deletions

View File

@ -2,9 +2,9 @@ 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")]
async fn main() -> Result<()> {
@ -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(&params.target_lang));
Ok(())
}