fix: add fallback to reverselookup error (#3025)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Kartikeya Hegde
2023-12-05 12:47:37 +05:30
committed by GitHub
parent 298e3627c3
commit ba392f58b2
14 changed files with 288 additions and 227 deletions

View File

@ -1,4 +1,4 @@
#[derive(Debug, thiserror::Error)]
#[derive(Copy, Clone, Debug, thiserror::Error)]
pub enum DatabaseError {
#[error("An error occurred when obtaining database connection")]
DatabaseConnectionError,
@ -14,3 +14,17 @@ pub enum DatabaseError {
#[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,
}
}
}