chore: change Result to anyhow::Result

This commit is contained in:
MedzikUser 2022-05-18 20:16:42 +02:00
parent 58acb3df50
commit 9b7705ed26
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
6 changed files with 6 additions and 11 deletions

View File

@ -1,11 +1,10 @@
use std::io;
use anyhow::Error;
use reqwest::Method;
use super::{client::api_url, send_api_request, ImgurClient};
pub async fn delete_image(client: &ImgurClient, delete_hash: &str) -> Result<(), Error> {
pub async fn delete_image(client: &ImgurClient, delete_hash: &str) -> anyhow::Result<()> {
// get imgur api url
let uri = api_url!(format!("image/{delete_hash}"));

View File

@ -1,11 +1,10 @@
use std::io;
use anyhow::Error;
use reqwest::Method;
use super::{client::api_url, send_api_request, ImageInfo, ImgurClient};
pub async fn get_image(client: &ImgurClient, image: &str) -> Result<ImageInfo, Error> {
pub async fn get_image(client: &ImgurClient, image: &str) -> anyhow::Result<ImageInfo> {
// get imgur api url
let uri = api_url!(format!("image/{image}"));

View File

@ -15,7 +15,6 @@ pub use upload_image::*;
use std::collections::HashMap;
use anyhow::Error;
use reqwest::{Method, Response};
// send request to imgur api
@ -24,7 +23,7 @@ pub async fn send_api_request(
method: Method,
uri: String,
form: Option<HashMap<&str, String>>,
) -> Result<Response, Error> {
) -> anyhow::Result<Response> {
// get request client
let client = &config.client;

View File

@ -1,6 +1,5 @@
use std::io;
use anyhow::Error;
use reqwest::Method;
use serde::{Deserialize, Serialize};
@ -27,7 +26,7 @@ pub struct RateLimitData {
pub client_remaining: i32,
}
pub async fn rate_limit(client: &ImgurClient) -> Result<RateLimitInfo, Error> {
pub async fn rate_limit(client: &ImgurClient) -> anyhow::Result<RateLimitInfo> {
// get imgur api url
let uri = api_url!("credits");

View File

@ -1,11 +1,10 @@
use std::{collections::HashMap, io};
use anyhow::Error;
use reqwest::Method;
use super::{client::api_url, send_api_request, ImageInfo, ImgurClient};
pub async fn upload_image(client: &ImgurClient, image: String) -> Result<ImageInfo, Error> {
pub async fn upload_image(client: &ImgurClient, image: String) -> anyhow::Result<ImageInfo> {
// create http form (hashmap)
let mut form = HashMap::new();
// insert image to form

View File

@ -50,7 +50,7 @@ pub fn parse() -> Config {
})
}
fn toml() -> Result<Config, Error> {
fn toml() -> anyhow::Result<Config> {
let config_dir = config_dir().unwrap();
let file_dir = format!("{}{CONFIG_DIR}", config_dir.to_string_lossy());
let toml_str = read_to_string(file_dir).map_err(Error::new)?;