mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-08 16:38:36 +08:00
feat(storage_impl): split payment intent interface implementation (#1946)
This commit is contained in:
@ -6,10 +6,11 @@ pub mod utils;
|
||||
use std::fmt::Display;
|
||||
|
||||
use actix_web::{body::BoxBody, http::StatusCode, ResponseError};
|
||||
use common_utils::errors::ErrorSwitch;
|
||||
pub use common_utils::errors::{CustomResult, ParsingError, ValidationError};
|
||||
use config::ConfigError;
|
||||
pub use data_models::errors::StorageError as DataStorageError;
|
||||
use diesel_models::errors as storage_errors;
|
||||
use error_stack;
|
||||
pub use redis_interface::errors::RedisError;
|
||||
use router_env::opentelemetry::metrics::MetricsError;
|
||||
|
||||
@ -80,6 +81,67 @@ pub enum StorageError {
|
||||
RedisError(error_stack::Report<RedisError>),
|
||||
}
|
||||
|
||||
impl ErrorSwitch<DataStorageError> for StorageError {
|
||||
fn switch(&self) -> DataStorageError {
|
||||
self.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::from_over_into)]
|
||||
impl Into<DataStorageError> for &StorageError {
|
||||
fn into(self) -> DataStorageError {
|
||||
match self {
|
||||
StorageError::DatabaseError(i) => match i.current_context() {
|
||||
storage_errors::DatabaseError::DatabaseConnectionError => {
|
||||
DataStorageError::DatabaseConnectionError
|
||||
}
|
||||
// TODO: Update this error type to encompass & propagate the missing type (instead of generic `db value not found`)
|
||||
storage_errors::DatabaseError::NotFound => {
|
||||
DataStorageError::ValueNotFound(String::from("db value not found"))
|
||||
}
|
||||
// TODO: Update this error type to encompass & propagate the duplicate type (instead of generic `db value not found`)
|
||||
storage_errors::DatabaseError::UniqueViolation => {
|
||||
DataStorageError::DuplicateValue {
|
||||
entity: "db entity",
|
||||
key: None,
|
||||
}
|
||||
}
|
||||
storage_errors::DatabaseError::NoFieldsToUpdate => {
|
||||
DataStorageError::DatabaseError("No fields to update".to_string())
|
||||
}
|
||||
storage_errors::DatabaseError::QueryGenerationFailed => {
|
||||
DataStorageError::DatabaseError("Query generation failed".to_string())
|
||||
}
|
||||
storage_errors::DatabaseError::Others => {
|
||||
DataStorageError::DatabaseError("Unknown database error".to_string())
|
||||
}
|
||||
},
|
||||
StorageError::ValueNotFound(i) => DataStorageError::ValueNotFound(i.clone()),
|
||||
StorageError::DuplicateValue { entity, key } => DataStorageError::DuplicateValue {
|
||||
entity,
|
||||
key: key.clone(),
|
||||
},
|
||||
StorageError::DatabaseConnectionError => DataStorageError::DatabaseConnectionError,
|
||||
StorageError::KVError => DataStorageError::KVError,
|
||||
StorageError::SerializationFailed => DataStorageError::SerializationFailed,
|
||||
StorageError::MockDbError => DataStorageError::MockDbError,
|
||||
StorageError::CustomerRedacted => DataStorageError::CustomerRedacted,
|
||||
StorageError::DeserializationFailed => DataStorageError::DeserializationFailed,
|
||||
StorageError::EncryptionError => DataStorageError::EncryptionError,
|
||||
StorageError::DecryptionError => DataStorageError::DecryptionError,
|
||||
StorageError::RedisError(i) => match i.current_context() {
|
||||
// TODO: Update this error type to encompass & propagate the missing type (instead of generic `redis value not found`)
|
||||
RedisError::NotFound => {
|
||||
DataStorageError::ValueNotFound("redis value not found".to_string())
|
||||
}
|
||||
RedisError::JsonSerializationFailed => DataStorageError::SerializationFailed,
|
||||
RedisError::JsonDeserializationFailed => DataStorageError::DeserializationFailed,
|
||||
i => DataStorageError::RedisError(format!("{:?}", i)),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<error_stack::Report<RedisError>> for StorageError {
|
||||
fn from(err: error_stack::Report<RedisError>) -> Self {
|
||||
Self::RedisError(err)
|
||||
|
||||
Reference in New Issue
Block a user