use std::collections::BTreeMap;
use std::panic::{catch_unwind, AssertUnwindSafe};
use std::time::Duration;
use super::error::Error;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct RequestInfo {
pub method: String,
pub url: String,
pub headers: BTreeMap<String, String>,
pub attempt: u32,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct ResponseInfo {
pub method: String,
pub url: String,
pub status: u16,
pub duration: Duration,
pub attempt: u32,
pub request_id: Option<String>,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct ErrorInfo {
pub method: String,
pub url: String,
pub error: Error,
pub attempt: u32,
pub will_retry: bool,
pub retry_delay: Option<Duration>,
}
pub trait Hooks: Send + Sync {
fn on_request(&self, _info: &RequestInfo) {}
fn on_response(&self, _info: &ResponseInfo) {}
fn on_error(&self, _info: &ErrorInfo) {}
}
pub(crate) fn guarded(f: impl FnOnce()) {
let _ = catch_unwind(AssertUnwindSafe(f));
}