Error handling refactor and 500 page/message templates

This commit is contained in:
Alphonse Paix
2025-09-20 04:06:48 +02:00
parent f5cd91108a
commit b52b676dc0
14 changed files with 223 additions and 201 deletions

View File

@@ -7,11 +7,11 @@ pub struct SubscriberEmail {
}
impl SubscriberEmail {
pub fn parse(email: String) -> Result<Self, String> {
pub fn parse(email: String) -> Result<Self, anyhow::Error> {
let subscriber_email = SubscriberEmail { email };
subscriber_email
.validate()
.map_err(|_| format!("{} is not a valid email.", subscriber_email.email))?;
if subscriber_email.validate().is_err() {
anyhow::bail!("{} is not a valid email.", subscriber_email.email);
}
Ok(subscriber_email)
}
}