Skip to content

Commit

Permalink
fix: return values unified
Browse files Browse the repository at this point in the history
The return values was not used.

On POST the HTTP error code is returned as an enum.
  • Loading branch information
lyager committed Mar 4, 2024
1 parent 8d0993e commit a6053b8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions plugins/upload/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum Error {
Request(#[from] reqwest::Error),
#[error("{0}")]
ContentLength(String),
#[error("{0}")]
HttpErrorCode(u16),
}

impl Serialize for Error {
Expand Down Expand Up @@ -100,7 +102,8 @@ async fn upload<R: Runtime>(

// Create the request and attach the file to the body
let client = reqwest::Client::new();
let mut request = client.post(url)
let mut request = client
.post(url)
.header(reqwest::header::CONTENT_LENGTH, file_len)
.body(file_to_body(id, window, file));

Expand All @@ -114,10 +117,7 @@ async fn upload<R: Runtime>(
if response.status().is_success() {
return response.text().await.map_err(Error::from);
}
Err(Error::ContentLength(format!(
"invalid status code: {}",
response.status().as_u16()
)))
Err(Error::HttpErrorCode(response.status().as_u16()))
}

fn file_to_body<R: Runtime>(id: u32, window: Window<R>, file: File) -> reqwest::Body {
Expand Down

0 comments on commit a6053b8

Please sign in to comment.