Fault-tolerant delivery system

This commit is contained in:
Alphonse Paix
2025-09-04 02:54:49 +02:00
parent 9a184b93ac
commit f8dee295cd
32 changed files with 872 additions and 120 deletions

View File

@@ -11,16 +11,17 @@ pub struct EmailClient {
}
impl EmailClient {
pub fn new(config: EmailClientSettings) -> Self {
Self {
pub fn build(config: EmailClientSettings) -> Result<Self, anyhow::Error> {
let client = Self {
http_client: Client::builder()
.timeout(Duration::from_millis(config.timeout_milliseconds))
.build()
.unwrap(),
base_url: reqwest::Url::parse(&config.base_url).unwrap(),
sender: config.sender().unwrap(),
base_url: reqwest::Url::parse(&config.base_url)?,
sender: config.sender().map_err(|e| anyhow::anyhow!(e))?,
authorization_token: config.authorization_token,
}
};
Ok(client)
}
pub async fn send_email(
@@ -125,7 +126,7 @@ mod tests {
let sender_email = SafeEmail().fake();
let token: String = Faker.fake();
let settings = EmailClientSettings::new(base_url, sender_email, token, 200);
EmailClient::new(settings)
EmailClient::build(settings).unwrap()
}
#[tokio::test]