cala_ledger/journal/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum JournalError {
5    #[error("JournalError - Sqlx: {0}")]
6    Sqlx(sqlx::Error),
7    #[error("JournalError - EsEntityError: {0}")]
8    EsEntityError(es_entity::EsEntityError),
9    #[error("JournalError - CursorDestructureError: {0}")]
10    CursorDestructureError(#[from] es_entity::CursorDestructureError),
11    #[error("JournalError - code already exists")]
12    CodeAlreadyExists,
13}
14
15impl From<sqlx::Error> for JournalError {
16    fn from(error: sqlx::Error) -> Self {
17        if let Some(err) = error.as_database_error() {
18            if let Some(constraint) = err.constraint() {
19                if constraint.contains("code") {
20                    return Self::CodeAlreadyExists;
21                }
22            }
23        }
24        Self::Sqlx(error)
25    }
26}
27
28es_entity::from_es_entity_error!(JournalError);