From 246dad5e87a71623009ad079cb01075d03ed608f Mon Sep 17 00:00:00 2001 From: Paul Z Date: Sun, 22 Oct 2023 19:03:03 +0200 Subject: [PATCH] improved error handling --- cli/Cargo.toml | 1 + cli/src/main.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index e7a9196..c37e72e 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -17,3 +17,4 @@ open = "5.0" tokio-util = { version="0.7.9", features = ["io"]} dirs = "5.0" confy = "0.5" +exitcode = "1.1.2" diff --git a/cli/src/main.rs b/cli/src/main.rs index 529294c..9fda8a5 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,3 +1,5 @@ +use std::process::ExitCode; + use clap::Parser; use reqwest::{Body, Url}; use serde::{Deserialize, Serialize}; @@ -84,11 +86,18 @@ async fn create_bin(binurl: &str, access_token: &str) -> Result Result<(), reqwest::Error> { let client = reqwest::Client::new(); - client + if let Err(error) = client .post(url) .header("Content-Type", content_type) .body(Body::wrap_stream(ReaderStream::new(stdin()))) .send() - .await?; + .await? + .text() + .await + { + eprintln!("{:?}", error); + std::process::exit(exitcode::TEMPFAIL); + } + Ok(()) }