feat: add zipline error type
This commit is contained in:
parent
0659698f19
commit
5a85e4f6c3
2 changed files with 26 additions and 29 deletions
|
@ -150,7 +150,6 @@ impl SimpleComponent for Toast {
|
|||
|
||||
pub struct StandaloneDialog;
|
||||
|
||||
// TODO: don't open a window, just give a HeaderBar to the dialog
|
||||
impl SimpleComponent for StandaloneDialog {
|
||||
type Init = String;
|
||||
type Input = ();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::{path::Path, sync::LazyLock};
|
||||
use std::{error::Error, fmt::Display, path::Path, sync::LazyLock};
|
||||
|
||||
use anyhow::{Result, bail};
|
||||
use anyhow::Result;
|
||||
use futures::StreamExt;
|
||||
use relm4::Sender;
|
||||
use reqwest::{
|
||||
|
@ -47,6 +47,25 @@ pub struct ZiplineShortUrl {
|
|||
url: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ZiplineError {
|
||||
error: String,
|
||||
status_code: usize,
|
||||
}
|
||||
|
||||
impl Display for ZiplineError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"An error occurred ({}): {}",
|
||||
self.status_code, self.error
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for ZiplineError {}
|
||||
|
||||
impl ZiplineFileInfo {
|
||||
pub fn thumbnail_url(&self, config: &Config) -> Option<String> {
|
||||
self.thumbnail
|
||||
|
@ -80,7 +99,6 @@ async fn wrap_file(path: &Path, sender: Sender<ProgressMessage>) -> Result<Part>
|
|||
})
|
||||
}
|
||||
|
||||
// TODO: make a ZiplineError type
|
||||
pub async fn get_folders(config: &Config) -> Result<Vec<ZiplineFolder>> {
|
||||
let url = format!("{}api/user/folders?noincl=true", config.fixed_url());
|
||||
|
||||
|
@ -91,11 +109,7 @@ pub async fn get_folders(config: &Config) -> Result<Vec<ZiplineFolder>> {
|
|||
.await?;
|
||||
|
||||
if res.status() != StatusCode::OK {
|
||||
bail!(
|
||||
"an error occurred ({}): {}",
|
||||
res.status(),
|
||||
res.text().await?
|
||||
);
|
||||
Err(res.json::<ZiplineError>().await?.into())
|
||||
} else {
|
||||
res.json().await.map_err(Into::into)
|
||||
}
|
||||
|
@ -125,11 +139,7 @@ pub async fn upload_file(
|
|||
let res = req.send().await?;
|
||||
|
||||
if res.status() != StatusCode::OK {
|
||||
bail!(
|
||||
"an error occurred ({}): {}",
|
||||
res.status(),
|
||||
res.text().await?
|
||||
);
|
||||
Err(res.json::<ZiplineError>().await?.into())
|
||||
} else {
|
||||
res.json().await.map_err(Into::into)
|
||||
}
|
||||
|
@ -146,11 +156,7 @@ pub async fn recalc_thumbnails(config: &Config) -> Result<()> {
|
|||
.await?;
|
||||
|
||||
if res.status() != StatusCode::OK {
|
||||
bail!(
|
||||
"an error occurred ({}): {}",
|
||||
res.status(),
|
||||
res.text().await?
|
||||
);
|
||||
Err(res.json::<ZiplineError>().await?.into())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -166,11 +172,7 @@ pub async fn get_file_details(config: &Config, id: &str) -> Result<ZiplineFileIn
|
|||
.await?;
|
||||
|
||||
if res.status() != StatusCode::OK {
|
||||
bail!(
|
||||
"an error occurred ({}): {}",
|
||||
res.status(),
|
||||
res.text().await?
|
||||
);
|
||||
Err(res.json::<ZiplineError>().await?.into())
|
||||
} else {
|
||||
res.json().await.map_err(Into::into)
|
||||
}
|
||||
|
@ -193,11 +195,7 @@ pub async fn shorten_url(config: &Config, to_shorten: &str) -> Result<String> {
|
|||
.await?;
|
||||
|
||||
if res.status() != StatusCode::OK {
|
||||
bail!(
|
||||
"an error occurred ({}): {}",
|
||||
res.status(),
|
||||
res.text().await?
|
||||
);
|
||||
Err(res.json::<ZiplineError>().await?.into())
|
||||
} else {
|
||||
let out: ZiplineShortUrl = res.json().await?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue