error message parsing problems
parent
498c963c20
commit
a725ab3928
|
|
@ -2,11 +2,11 @@ mod engine;
|
||||||
|
|
||||||
use crate::engine::params::Params;
|
use crate::engine::params::Params;
|
||||||
use crate::engine::response::DeeplResponse;
|
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 hyper_tls::HttpsConnector;
|
||||||
use anyhow::Result;
|
|
||||||
|
|
||||||
#[tokio::main(flavor = "current_thread")]
|
#[tokio::main(flavor = "current_thread")]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let https = HttpsConnector::new();
|
let https = HttpsConnector::new();
|
||||||
let client = Client::builder().build::<_, hyper::Body>(https);
|
let client = Client::builder().build::<_, hyper::Body>(https);
|
||||||
|
|
@ -22,7 +22,8 @@ async fn main() -> Result<()> {
|
||||||
let res = client.request(request).await?;
|
let res = client.request(request).await?;
|
||||||
let body_bytes = body::to_bytes(res.into_body()).await?;
|
let body_bytes = body::to_bytes(res.into_body()).await?;
|
||||||
let body = String::from_utf8(body_bytes.to_vec())?;
|
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));
|
println!("{}", v.get_text(¶ms.target_lang));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue