mirror of https://github.com/MedzikUser/imgurs
chore: rename anyhow_err to anyhow::Error
This commit is contained in:
parent
4ad662e35e
commit
a591d427f3
|
@ -1,25 +1,23 @@
|
|||
use crate::api::configuration::{api_url, ImgurClient};
|
||||
|
||||
use super::send_api_request;
|
||||
|
||||
use anyhow::Error as anyhow_err;
|
||||
use reqwest::Method;
|
||||
use std::io::{Error, ErrorKind};
|
||||
|
||||
pub async fn delete_image(c: ImgurClient, delete_hash: String) -> Result<String, anyhow_err> {
|
||||
pub async fn delete_image(c: ImgurClient, delete_hash: String) -> Result<String, anyhow::Error> {
|
||||
let uri = api_url!(format!("image/{delete_hash}"));
|
||||
let res = send_api_request(&c, Method::DELETE, uri, None).await?;
|
||||
|
||||
let status = res.status();
|
||||
|
||||
if status.is_client_error() || status.is_server_error() {
|
||||
let body = res.text().await.map_err(anyhow_err::new)?;
|
||||
let body = res.text().await.map_err(anyhow::Error::new)?;
|
||||
let err = Error::new(
|
||||
ErrorKind::Other,
|
||||
format!("server returned non-successful status code = {status}, body = {body}"),
|
||||
);
|
||||
|
||||
Err(anyhow_err::from(err))
|
||||
Err(anyhow::Error::from(err))
|
||||
} else {
|
||||
Ok("If the delete hash was correct the image was deleted!".to_string())
|
||||
}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
use crate::api::configuration::{api_url, ImgurClient};
|
||||
use crate::api::ImageInfo;
|
||||
|
||||
use super::send_api_request;
|
||||
|
||||
use anyhow::Error as anyhow_err;
|
||||
use reqwest::Method;
|
||||
use std::io::{Error, ErrorKind};
|
||||
|
||||
pub async fn get_image(c: ImgurClient, image: &str) -> Result<ImageInfo, anyhow_err> {
|
||||
pub async fn get_image(c: ImgurClient, image: &str) -> Result<ImageInfo, anyhow::Error> {
|
||||
let uri = api_url!(format!("image/{image}"));
|
||||
let res = send_api_request(&c, Method::GET, uri, None).await?;
|
||||
|
||||
|
@ -19,9 +17,9 @@ pub async fn get_image(c: ImgurClient, image: &str) -> Result<ImageInfo, anyhow_
|
|||
format!("server returned non-successful status code = {status}"),
|
||||
);
|
||||
|
||||
Err(anyhow_err::from(err))
|
||||
Err(anyhow::Error::from(err))
|
||||
} else {
|
||||
let content: ImageInfo = res.json().await.map_err(anyhow_err::new)?;
|
||||
let content: ImageInfo = res.json().await.map_err(anyhow::Error::new)?;
|
||||
Ok(content)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
use crate::api::configuration::{api_url, ImgurClient};
|
||||
|
||||
use super::send_api_request;
|
||||
|
||||
use anyhow::Error as anyhow_err;
|
||||
use reqwest::Method;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::io::{Error, ErrorKind};
|
||||
|
@ -28,22 +26,22 @@ pub struct RateLimitData {
|
|||
pub client_remaining: i32,
|
||||
}
|
||||
|
||||
pub async fn rate_limit(c: ImgurClient) -> Result<RateLimitInfo, anyhow_err> {
|
||||
pub async fn rate_limit(c: ImgurClient) -> Result<RateLimitInfo, anyhow::Error> {
|
||||
let uri = api_url!("credits");
|
||||
let res = send_api_request(&c, Method::GET, uri, None).await?;
|
||||
|
||||
let status = res.status();
|
||||
|
||||
if status.is_client_error() || status.is_server_error() {
|
||||
let body = res.text().await.map_err(anyhow_err::new)?;
|
||||
let body = res.text().await.map_err(anyhow::Error::new)?;
|
||||
let err = Error::new(
|
||||
ErrorKind::Other,
|
||||
format!("server returned non-successful status code = {status}, body = {body}"),
|
||||
);
|
||||
|
||||
Err(anyhow_err::from(err))
|
||||
Err(anyhow::Error::from(err))
|
||||
} else {
|
||||
let content: RateLimitInfo = res.json().await.map_err(anyhow_err::new)?;
|
||||
let content: RateLimitInfo = res.json().await.map_err(anyhow::Error::new)?;
|
||||
Ok(content)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ fn is_program_in_path(program: &str) -> bool {
|
|||
for p in path.split(":") {
|
||||
let p_str = format!("{}/{}", p, program);
|
||||
if fs::metadata(p_str).is_ok() {
|
||||
return true;
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue