diff --git a/crates/application/src/use_cases/auth.rs b/crates/application/src/use_cases/auth.rs index b717733..d59001c 100644 --- a/crates/application/src/use_cases/auth.rs +++ b/crates/application/src/use_cases/auth.rs @@ -38,11 +38,15 @@ pub async fn register( .save(&user) .await .map_err(|e| match e { - DomainError::Conflict(c) => match c.as_str() { - "users_username_key" => DomainError::Conflict("username taken".into()), - "users_email_key" => DomainError::Conflict("email taken".into()), - _ => DomainError::Conflict("already exists".into()), - }, + DomainError::UniqueViolation { field: "username" } => { + DomainError::Conflict("username taken".into()) + } + DomainError::UniqueViolation { field: "email" } => { + DomainError::Conflict("email taken".into()) + } + DomainError::UniqueViolation { .. } => { + DomainError::Conflict("already exists".into()) + } other => other, })?; events @@ -136,7 +140,7 @@ mod tests { #[async_trait] impl UserWriter for ConflictOnSaveStore { async fn save(&self, _user: &User) -> Result<(), DomainError> { - Err(DomainError::Conflict("users_username_key".into())) + Err(DomainError::UniqueViolation { field: "username" }) } async fn update_profile( &self, @@ -178,7 +182,7 @@ mod tests { #[async_trait] impl UserWriter for EmailConflictOnSaveStore { async fn save(&self, _user: &User) -> Result<(), DomainError> { - Err(DomainError::Conflict("users_email_key".into())) + Err(DomainError::UniqueViolation { field: "email" }) } async fn update_profile( &self,