mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
refactor(errors): add parsing error types for context info (#911)
This commit is contained in:
@ -735,7 +735,8 @@ fn get_webhook_object_from_body(
|
||||
.notification_items
|
||||
.drain(..)
|
||||
.next()
|
||||
.ok_or(errors::ParsingError)
|
||||
// TODO: ParsingError doesn't seem to be an apt error for this case
|
||||
.ok_or(errors::ParsingError::UnknownError)
|
||||
.into_report()?;
|
||||
|
||||
Ok(item_object.notification_request_item)
|
||||
|
||||
@ -106,7 +106,7 @@ impl StorageInterface for MockDb {}
|
||||
pub async fn get_and_deserialize_key<T>(
|
||||
db: &dyn StorageInterface,
|
||||
key: &str,
|
||||
type_name: &str,
|
||||
type_name: &'static str,
|
||||
) -> common_utils::errors::CustomResult<T, redis_interface::errors::RedisError>
|
||||
where
|
||||
T: serde::de::DeserializeOwned,
|
||||
|
||||
@ -48,7 +48,7 @@ impl ConnectorAccessToken for Store {
|
||||
let access_token: Option<types::AccessToken> = maybe_token
|
||||
.map(|token| token.parse_struct("AccessToken"))
|
||||
.transpose()
|
||||
.change_context(errors::ParsingError)
|
||||
.change_context(errors::ParsingError::UnknownError)
|
||||
.change_context(errors::StorageError::DeserializationFailed)?;
|
||||
|
||||
Ok(access_token)
|
||||
|
||||
@ -83,7 +83,7 @@ impl ProcessTrackerBatch {
|
||||
.as_str()
|
||||
.parse()
|
||||
.into_report()
|
||||
.change_context(errors::ParsingError)
|
||||
.change_context(errors::ParsingError::UnknownError)
|
||||
.change_context(errors::ProcessTrackerError::DeserializationFailed)?,
|
||||
)
|
||||
.into_report()
|
||||
@ -105,7 +105,7 @@ impl ProcessTrackerBatch {
|
||||
|
||||
let trackers = serde_json::from_str::<Vec<ProcessTracker>>(trackers.as_str())
|
||||
.into_report()
|
||||
.change_context(errors::ParsingError)
|
||||
.change_context(errors::ParsingError::UnknownError)
|
||||
.attach_printable_lazy(|| {
|
||||
format!("Unable to parse trackers from JSON string: {trackers:?}")
|
||||
})
|
||||
|
||||
@ -76,7 +76,7 @@ pub fn generate_id(length: usize, prefix: &str) -> String {
|
||||
pub trait ConnectorResponseExt: Sized {
|
||||
fn get_response(self) -> RouterResult<types::Response>;
|
||||
fn get_error_response(self) -> RouterResult<types::Response>;
|
||||
fn get_response_inner<T: DeserializeOwned>(self, type_name: &str) -> RouterResult<T> {
|
||||
fn get_response_inner<T: DeserializeOwned>(self, type_name: &'static str) -> RouterResult<T> {
|
||||
self.get_response()?
|
||||
.response
|
||||
.parse_struct(type_name)
|
||||
|
||||
@ -57,11 +57,11 @@ where
|
||||
{
|
||||
let value = self
|
||||
.get_required_value(enum_name)
|
||||
.change_context(errors::ParsingError)?;
|
||||
.change_context(errors::ParsingError::UnknownError)?;
|
||||
|
||||
E::from_str(value.as_ref())
|
||||
.into_report()
|
||||
.change_context(errors::ParsingError)
|
||||
.change_context(errors::ParsingError::UnknownError)
|
||||
.attach_printable_lazy(|| format!("Invalid {{ {enum_name}: {value:?} }} "))
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ where
|
||||
{
|
||||
let value = self
|
||||
.get_required_value(type_name)
|
||||
.change_context(errors::ParsingError)?;
|
||||
.change_context(errors::ParsingError::UnknownError)?;
|
||||
value.parse_value(type_name)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user