Fault-tolerant delivery system
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user