Implemented debug logging to debug_logs/
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use reqwest::{Client, Url};
|
||||
use reqwest::Url;
|
||||
use reqwest_middleware::ClientWithMiddleware;
|
||||
use serde::de::DeserializeOwned;
|
||||
use thiserror::Error;
|
||||
use tracing::instrument;
|
||||
@@ -8,6 +9,8 @@ use crate::models::{AccountArray, TransactionStore, TransactionArray, Transactio
|
||||
pub enum FireflyError {
|
||||
#[error("Request failed: {0}")]
|
||||
RequestFailed(#[from] reqwest::Error),
|
||||
#[error("Middleware error: {0}")]
|
||||
MiddlewareError(#[from] reqwest_middleware::Error),
|
||||
#[error("API Error: {0}")]
|
||||
ApiError(String),
|
||||
#[error("URL Parse Error: {0}")]
|
||||
@@ -16,15 +19,19 @@ pub enum FireflyError {
|
||||
|
||||
pub struct FireflyClient {
|
||||
base_url: Url,
|
||||
client: Client,
|
||||
client: ClientWithMiddleware,
|
||||
access_token: String,
|
||||
}
|
||||
|
||||
impl FireflyClient {
|
||||
pub fn new(base_url: &str, access_token: &str) -> Result<Self, FireflyError> {
|
||||
Self::with_client(base_url, access_token, None)
|
||||
}
|
||||
|
||||
pub fn with_client(base_url: &str, access_token: &str, client: Option<ClientWithMiddleware>) -> Result<Self, FireflyError> {
|
||||
Ok(Self {
|
||||
base_url: Url::parse(base_url)?,
|
||||
client: Client::new(),
|
||||
client: client.unwrap_or_else(|| reqwest_middleware::ClientBuilder::new(reqwest::Client::new()).build()),
|
||||
access_token: access_token.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user