hoprd_db_api/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use sea_orm::TransactionError;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum DbError {
    #[error("alias not found: {0}")]
    AliasNotFound(String),

    #[error("re-aliasing self is not allowed")]
    ReAliasingSelfNotAllowed,

    #[error("alias or peer id already exists")]
    AliasOrPeerIdAlreadyExists,

    #[error("transaction error: {0}")]
    TransactionError(Box<dyn std::error::Error + Send + Sync>),

    #[error("logical error: {0}")]
    LogicalError(String),

    #[error(transparent)]
    BackendError(#[from] sea_orm::DbErr),
}

impl<E: std::error::Error + Send + Sync + 'static> From<TransactionError<E>> for DbError {
    fn from(value: TransactionError<E>) -> Self {
        match value {
            TransactionError::Connection(e) => Self::BackendError(e),
            TransactionError::Transaction(e) => Self::TransactionError(Box::new(e)),
        }
    }
}

pub type Result<T> = std::result::Result<T, DbError>;