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 accounts;
pub mod dtos; pub mod dtos;
mod error_codes;
pub mod recurring_transactions; pub mod recurring_transactions;
pub mod transactions; pub mod transactions;
use error_codes::PG_FOREIGN_KEY_VIOLATION;
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum DatabaseError { pub enum DatabaseError {
#[error("foreign key violation ({constraint}): {source}")] #[error("foreign key violation ({constraint}): {source}")]
@@ -19,7 +22,9 @@ pub enum DatabaseError {
impl From<sqlx::Error> for DatabaseError { impl From<sqlx::Error> for DatabaseError {
fn from(err: sqlx::Error) -> Self { fn from(err: sqlx::Error) -> Self {
match err { 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 let constraint = db_err
.constraint() .constraint()
.map(Constraint::from) .map(Constraint::from)
+1
View File
@@ -0,0 +1 @@
pub const PG_FOREIGN_KEY_VIOLATION: &str = "23503";