Files
Kartikeya Hegde ba392f58b2 fix: add fallback to reverselookup error (#3025)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
2023-12-05 07:17:37 +00:00

31 lines
1.1 KiB
Rust

#[derive(Copy, Clone, Debug, thiserror::Error)]
pub enum DatabaseError {
#[error("An error occurred when obtaining database connection")]
DatabaseConnectionError,
#[error("The requested resource was not found in the database")]
NotFound,
#[error("A unique constraint violation occurred")]
UniqueViolation,
#[error("No fields were provided to be updated")]
NoFieldsToUpdate,
#[error("An error occurred when generating typed SQL query")]
QueryGenerationFailed,
// InsertFailed,
#[error("An unknown error occurred")]
Others,
}
impl From<diesel::result::Error> for DatabaseError {
fn from(error: diesel::result::Error) -> Self {
match error {
diesel::result::Error::DatabaseError(
diesel::result::DatabaseErrorKind::UniqueViolation,
_,
) => Self::UniqueViolation,
diesel::result::Error::NotFound => Self::NotFound,
diesel::result::Error::QueryBuilderError(_) => Self::QueryGenerationFailed,
_ => Self::Others,
}
}
}