Files
thoughts/crates/adapters/postgres/src/db_error.rs
Gabriel Kaszewski 9aee4ceb6d
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
feat: v2 rewrite — hexagonal arch, ActivityPub federation, NATS, deployment-ready (#1)
2026-05-16 09:42:40 +00:00

21 lines
619 B
Rust

use domain::errors::DomainError;
pub(crate) trait IntoDbResult<T> {
fn into_domain(self) -> Result<T, DomainError>;
}
impl<T> IntoDbResult<T> for Result<T, sqlx::Error> {
fn into_domain(self) -> Result<T, DomainError> {
self.map_err(|e| {
if let sqlx::Error::Database(ref db) = e {
if db.code().as_deref() == Some("23505") {
return DomainError::Conflict(
db.constraint().unwrap_or("conflict").to_string(),
);
}
}
DomainError::Internal(e.to_string())
})
}
}