improved error handling

This commit is contained in:
Paul Zinselmeyer 2023-10-22 19:03:03 +02:00
parent 562475f242
commit 1410bda48e
2 changed files with 12 additions and 2 deletions

View file

@ -17,3 +17,4 @@ open = "5.0"
tokio-util = { version="0.7.9", features = ["io"]} tokio-util = { version="0.7.9", features = ["io"]}
dirs = "5.0" dirs = "5.0"
confy = "0.5" confy = "0.5"
exitcode = "1.1.2"

View file

@ -1,3 +1,5 @@
use std::process::ExitCode;
use clap::Parser; use clap::Parser;
use reqwest::{Body, Url}; use reqwest::{Body, Url};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -84,11 +86,18 @@ async fn create_bin(binurl: &str, access_token: &str) -> Result<Url, reqwest::Er
async fn upload_to_bin(url: &str, content_type: &str) -> Result<(), reqwest::Error> { async fn upload_to_bin(url: &str, content_type: &str) -> Result<(), reqwest::Error> {
let client = reqwest::Client::new(); let client = reqwest::Client::new();
client if let Err(error) = client
.post(url) .post(url)
.header("Content-Type", content_type) .header("Content-Type", content_type)
.body(Body::wrap_stream(ReaderStream::new(stdin()))) .body(Body::wrap_stream(ReaderStream::new(stdin())))
.send() .send()
.await?; .await?
.text()
.await
{
eprintln!("{:?}", error);
std::process::exit(exitcode::TEMPFAIL);
}
Ok(()) Ok(())
} }