From 33e064a289b75a220e9f879018e7386251607033 Mon Sep 17 00:00:00 2001 From: ForgQi <34411314+ForgQi@users.noreply.github.com> Date: Fri, 29 Jul 2022 08:59:58 +0800 Subject: [PATCH] complete error handling --- src/cli.rs | 3 ++- src/line.rs | 14 +++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 70cb2ba..77955ff 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -292,7 +292,8 @@ pub async fn upload( // let line = line::kodo(); for video_path in video_path { println!("{line:?}"); - let video_file = VideoFile::new(video_path)?; + let video_file = VideoFile::new(video_path) + .with_context(|| format!("file {}", video_path.to_string_lossy()))?; let total_size = video_file.total_size; let file_name = video_file.file_name.clone(); let uploader = line.to_uploader(video_file); diff --git a/src/line.rs b/src/line.rs index 9c8284a..ae6a8e7 100644 --- a/src/line.rs +++ b/src/line.rs @@ -49,7 +49,7 @@ impl<'a> Parcel<'a> { } pub async fn pre_upload(&self, login: &Client) -> Result { - Ok(login + let response = login .client .get(format!( "https://member.bilibili.com/preupload?{}", @@ -57,10 +57,14 @@ impl<'a> Parcel<'a> { )) .query(&self.params) .send() - .await? - .json() - .await - .with_context(|| "Failed to pre_upload from")?) + .await?; + let full = response.bytes().await?; + Ok(serde_json::from_slice(&full).with_context(|| { + format!( + "Failed to pre_upload from {}", + String::from_utf8_lossy(&full) + ) + })?) } pub async fn upload(&self, client: &Client, limit: usize, progress: F) -> Result