Implemented debug logging to debug_logs/

This commit is contained in:
2025-11-21 17:04:31 +01:00
parent f7e96bcf35
commit cf5e6eee08
10 changed files with 228 additions and 13 deletions

View File

@@ -5,7 +5,8 @@ edition.workspace = true
authors.workspace = true
[dependencies]
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
reqwest = { workspace = true, default-features = false, features = ["json", "rustls-tls"] }
reqwest-middleware = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
thiserror = { workspace = true }

View File

@@ -1,4 +1,5 @@
use reqwest::{Client, Url};
use reqwest::Url;
use reqwest_middleware::ClientWithMiddleware;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use tracing::{debug, instrument};
@@ -8,6 +9,8 @@ use crate::models::{TokenResponse, PaginatedResponse, Requisition, Account, Tran
pub enum GoCardlessError {
#[error("Request failed: {0}")]
RequestFailed(#[from] reqwest::Error),
#[error("Middleware error: {0}")]
MiddlewareError(#[from] reqwest_middleware::Error),
#[error("API Error: {0}")]
ApiError(String),
#[error("Serialization error: {0}")]
@@ -18,7 +21,7 @@ pub enum GoCardlessError {
pub struct GoCardlessClient {
base_url: Url,
client: Client,
client: ClientWithMiddleware,
secret_id: String,
secret_key: String,
access_token: Option<String>,
@@ -33,9 +36,13 @@ struct TokenRequest<'a> {
impl GoCardlessClient {
pub fn new(base_url: &str, secret_id: &str, secret_key: &str) -> Result<Self, GoCardlessError> {
Self::with_client(base_url, secret_id, secret_key, None)
}
pub fn with_client(base_url: &str, secret_id: &str, secret_key: &str, client: Option<ClientWithMiddleware>) -> Result<Self, GoCardlessError> {
Ok(Self {
base_url: Url::parse(base_url)?,
client: Client::new(),
client: client.unwrap_or_else(|| reqwest_middleware::ClientBuilder::new(reqwest::Client::new()).build()),
secret_id: secret_id.to_string(),
secret_key: secret_key.to_string(),
access_token: None,