Error codes file.

This commit is contained in:
2026-09-28 07:07:59 +02:00
parent e2742eee27
commit 9a3c03d451
2 changed files with 7 additions and 1 deletions
+6 -1
View File
@@ -1,8 +1,11 @@
pub mod accounts;
pub mod dtos;
mod error_codes;
pub mod recurring_transactions;
pub mod transactions;
use error_codes::PG_FOREIGN_KEY_VIOLATION;
#[derive(Debug, thiserror::Error)]
pub enum DatabaseError {
#[error("foreign key violation ({constraint}): {source}")]
@@ -19,7 +22,9 @@ pub enum DatabaseError {
impl From<sqlx::Error> for DatabaseError {
fn from(err: sqlx::Error) -> Self {
match err {
sqlx::Error::Database(db_err) if db_err.code().as_deref() == Some("23503") => {
sqlx::Error::Database(db_err)
if db_err.code().as_deref() == Some(PG_FOREIGN_KEY_VIOLATION) =>
{
let constraint = db_err
.constraint()
.map(Constraint::from)