Error handling refactor and 500 page/message templates
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user