mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 09:38:33 +08:00
refactor(router): make error_type generic in domain_models inorder to avoid conversion of errors in storage_impl (#7537)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,51 +1 @@
|
||||
pub mod api_error_response;
|
||||
use diesel_models::errors::DatabaseError;
|
||||
|
||||
pub type StorageResult<T> = error_stack::Result<T, StorageError>;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum StorageError {
|
||||
#[error("Initialization Error")]
|
||||
InitializationError,
|
||||
// TODO: deprecate this error type to use a domain error instead
|
||||
#[error("DatabaseError: {0:?}")]
|
||||
DatabaseError(error_stack::Report<DatabaseError>),
|
||||
#[error("ValueNotFound: {0}")]
|
||||
ValueNotFound(String),
|
||||
#[error("DuplicateValue: {entity} already exists {key:?}")]
|
||||
DuplicateValue {
|
||||
entity: &'static str,
|
||||
key: Option<String>,
|
||||
},
|
||||
#[error("Timed out while trying to connect to the database")]
|
||||
DatabaseConnectionError,
|
||||
#[error("KV error")]
|
||||
KVError,
|
||||
#[error("Serialization failure")]
|
||||
SerializationFailed,
|
||||
#[error("MockDb error")]
|
||||
MockDbError,
|
||||
#[error("Kafka error")]
|
||||
KafkaError,
|
||||
#[error("Customer with this id is Redacted")]
|
||||
CustomerRedacted,
|
||||
#[error("Deserialization failure")]
|
||||
DeserializationFailed,
|
||||
#[error("Error while encrypting data")]
|
||||
EncryptionError,
|
||||
#[error("Error while decrypting data from database")]
|
||||
DecryptionError,
|
||||
// TODO: deprecate this error type to use a domain error instead
|
||||
#[error("RedisError: {0:?}")]
|
||||
RedisError(String),
|
||||
}
|
||||
|
||||
impl StorageError {
|
||||
pub fn is_db_not_found(&self) -> bool {
|
||||
match self {
|
||||
Self::DatabaseError(err) => matches!(err.current_context(), DatabaseError::NotFound),
|
||||
Self::ValueNotFound(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user