mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 23:02:31 +00:00
40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
#[derive(Debug, thiserror::Error)]
|
|
pub enum Error {
|
|
#[error(transparent)]
|
|
SqlxError(sqlx::Error),
|
|
|
|
#[error(transparent)]
|
|
StoreError(rustical_store::Error),
|
|
}
|
|
|
|
impl From<sqlx::Error> for Error {
|
|
fn from(value: sqlx::Error) -> Self {
|
|
match value {
|
|
sqlx::Error::RowNotFound => Error::StoreError(rustical_store::Error::NotFound),
|
|
sqlx::Error::Database(err) => {
|
|
if err.is_unique_violation() {
|
|
Error::StoreError(rustical_store::Error::AlreadyExists)
|
|
} else {
|
|
Error::SqlxError(sqlx::Error::Database(err))
|
|
}
|
|
}
|
|
err => Error::SqlxError(err),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<Error> for rustical_store::Error {
|
|
fn from(value: Error) -> Self {
|
|
match value {
|
|
Error::SqlxError(err) => Self::Other(err.into()),
|
|
Error::StoreError(err) => err,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<rustical_store::Error> for Error {
|
|
fn from(value: rustical_store::Error) -> Self {
|
|
Self::StoreError(value)
|
|
}
|
|
}
|