mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
build(deps): bump error-stack from version 0.3.1 to 0.4.1 (#4188)
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
use common_utils::request::{Method, Request, RequestBuilder, RequestContent};
|
||||
use error_stack::{IntoReport, ResultExt};
|
||||
use error_stack::ResultExt;
|
||||
use http::header;
|
||||
|
||||
use crate::{
|
||||
@ -28,17 +28,16 @@ pub async fn generate_access_token(state: AppState) -> RouterResult<types::Acces
|
||||
verify_connector_types::VerifyConnectorData {
|
||||
connector: *boxed_connector,
|
||||
connector_auth,
|
||||
card_details: verify_connector_utils::get_test_card_details(connector)?
|
||||
.ok_or(ApiErrorResponse::FlowNotSupported {
|
||||
card_details: verify_connector_utils::get_test_card_details(connector)?.ok_or(
|
||||
ApiErrorResponse::FlowNotSupported {
|
||||
flow: "Connector onboarding".to_string(),
|
||||
connector: connector.to_string(),
|
||||
})
|
||||
.into_report()?,
|
||||
},
|
||||
)?,
|
||||
},
|
||||
)
|
||||
.await?
|
||||
.ok_or(ApiErrorResponse::InternalServerError)
|
||||
.into_report()
|
||||
.attach_printable("Error occurred while retrieving access token")
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ use std::{collections::HashMap, ops::Deref, str::FromStr, sync::Arc, time::Durat
|
||||
use api_models::enums;
|
||||
use common_utils::{date_time, errors::CustomResult, events::ApiEventMetric, ext_traits::AsyncExt};
|
||||
use currency_conversion::types::{CurrencyFactors, ExchangeRates};
|
||||
use error_stack::{IntoReport, ResultExt};
|
||||
use error_stack::ResultExt;
|
||||
use masking::PeekInterface;
|
||||
use once_cell::sync::Lazy;
|
||||
use redis_interface::DelReply;
|
||||
@ -150,12 +150,10 @@ impl TryFrom<DefaultExchangeRates> for ExchangeRates {
|
||||
let mut conversion_usable: HashMap<enums::Currency, CurrencyFactors> = HashMap::new();
|
||||
for (curr, conversion) in value.conversion {
|
||||
let enum_curr = enums::Currency::from_str(curr.as_str())
|
||||
.into_report()
|
||||
.change_context(ForexCacheError::ConversionError)?;
|
||||
conversion_usable.insert(enum_curr, CurrencyFactors::from(conversion));
|
||||
}
|
||||
let base_curr = enums::Currency::from_str(value.base_currency.as_str())
|
||||
.into_report()
|
||||
.change_context(ForexCacheError::ConversionError)?;
|
||||
Ok(Self {
|
||||
base_currency: base_curr,
|
||||
@ -342,7 +340,6 @@ async fn fetch_forex_rates(
|
||||
let forex_response = response
|
||||
.json::<ForexResponse>()
|
||||
.await
|
||||
.into_report()
|
||||
.change_context(ForexCacheError::ParsingError)?;
|
||||
|
||||
logger::info!("{:?}", forex_response);
|
||||
@ -399,7 +396,6 @@ pub async fn fallback_fetch_forex_rates(
|
||||
let fallback_forex_response = response
|
||||
.json::<FallbackForexResponse>()
|
||||
.await
|
||||
.into_report()
|
||||
.change_context(ForexCacheError::ParsingError)?;
|
||||
|
||||
logger::info!("{:?}", fallback_forex_response);
|
||||
@ -463,11 +459,11 @@ async fn acquire_redis_lock(app_state: &AppState) -> CustomResult<bool, ForexCac
|
||||
REDIX_FOREX_CACHE_KEY,
|
||||
"",
|
||||
Some(
|
||||
(forex_api.local_fetch_retry_count * forex_api.local_fetch_retry_delay
|
||||
+ forex_api.api_timeout)
|
||||
.try_into()
|
||||
.into_report()
|
||||
.change_context(ForexCacheError::ConversionError)?,
|
||||
i64::try_from(
|
||||
forex_api.local_fetch_retry_count * forex_api.local_fetch_retry_delay
|
||||
+ forex_api.api_timeout,
|
||||
)
|
||||
.change_context(ForexCacheError::ConversionError)?,
|
||||
),
|
||||
)
|
||||
.await
|
||||
@ -530,16 +526,13 @@ pub async fn convert_currency(
|
||||
.change_context(ForexCacheError::ApiError)?;
|
||||
|
||||
let to_currency = api_models::enums::Currency::from_str(to_currency.as_str())
|
||||
.into_report()
|
||||
.change_context(ForexCacheError::CurrencyNotAcceptable)?;
|
||||
|
||||
let from_currency = api_models::enums::Currency::from_str(from_currency.as_str())
|
||||
.into_report()
|
||||
.change_context(ForexCacheError::CurrencyNotAcceptable)?;
|
||||
|
||||
let converted_amount =
|
||||
currency_conversion::conversion::convert(&rates.data, from_currency, to_currency, amount)
|
||||
.into_report()
|
||||
.change_context(ForexCacheError::ConversionError)?;
|
||||
|
||||
Ok(api_models::currency::CurrencyConversionResponse {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use common_utils::ext_traits::ValueExt;
|
||||
use error_stack::{IntoReport, Report, ResultExt};
|
||||
use error_stack::{Report, ResultExt};
|
||||
|
||||
use crate::{
|
||||
core::errors::{self, ApiErrorResponse, CustomResult, RouterResult},
|
||||
@ -62,7 +62,6 @@ where
|
||||
.change_context(errors::ParsingError::UnknownError)?;
|
||||
|
||||
E::from_str(value.as_ref())
|
||||
.into_report()
|
||||
.change_context(errors::ParsingError::UnknownError)
|
||||
.attach_printable_lazy(|| format!("Invalid {{ {enum_name}: {value:?} }} "))
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||
use api_models::user as user_api;
|
||||
use common_utils::errors::CustomResult;
|
||||
use diesel_models::{enums::UserStatus, user_role::UserRole};
|
||||
use error_stack::ResultExt;
|
||||
use error_stack::{report, ResultExt};
|
||||
use masking::{ExposeInterface, Secret};
|
||||
|
||||
use crate::{
|
||||
@ -148,7 +148,7 @@ pub fn get_multiple_merchant_details_with_status(
|
||||
.map(|merchant| {
|
||||
let role = roles
|
||||
.get(merchant.merchant_id.as_str())
|
||||
.ok_or(UserErrors::InternalServerError.into())
|
||||
.ok_or(report!(UserErrors::InternalServerError))
|
||||
.attach_printable("Merchant exists but user role doesn't")?;
|
||||
|
||||
Ok(user_api::UserMerchantAccount {
|
||||
|
||||
@ -8,7 +8,7 @@ use diesel_models::{
|
||||
enums::DashboardMetadata as DBEnum,
|
||||
user::dashboard_metadata::{DashboardMetadata, DashboardMetadataNew, DashboardMetadataUpdate},
|
||||
};
|
||||
use error_stack::{IntoReport, ResultExt};
|
||||
use error_stack::{report, ResultExt};
|
||||
use masking::Secret;
|
||||
|
||||
use crate::{
|
||||
@ -26,7 +26,6 @@ pub async fn insert_merchant_scoped_metadata_to_db(
|
||||
) -> UserResult<DashboardMetadata> {
|
||||
let now = common_utils::date_time::now();
|
||||
let data_value = serde_json::to_value(metadata_value)
|
||||
.into_report()
|
||||
.change_context(UserErrors::InternalServerError)
|
||||
.attach_printable("Error Converting Struct To Serde Value")?;
|
||||
state
|
||||
@ -60,7 +59,6 @@ pub async fn insert_user_scoped_metadata_to_db(
|
||||
) -> UserResult<DashboardMetadata> {
|
||||
let now = common_utils::date_time::now();
|
||||
let data_value = serde_json::to_value(metadata_value)
|
||||
.into_report()
|
||||
.change_context(UserErrors::InternalServerError)
|
||||
.attach_printable("Error Converting Struct To Serde Value")?;
|
||||
state
|
||||
@ -131,7 +129,6 @@ pub async fn update_merchant_scoped_metadata(
|
||||
metadata_value: impl serde::Serialize,
|
||||
) -> UserResult<DashboardMetadata> {
|
||||
let data_value = serde_json::to_value(metadata_value)
|
||||
.into_report()
|
||||
.change_context(UserErrors::InternalServerError)
|
||||
.attach_printable("Error Converting Struct To Serde Value")?;
|
||||
|
||||
@ -160,7 +157,6 @@ pub async fn update_user_scoped_metadata(
|
||||
metadata_value: impl serde::Serialize,
|
||||
) -> UserResult<DashboardMetadata> {
|
||||
let data_value = serde_json::to_value(metadata_value)
|
||||
.into_report()
|
||||
.change_context(UserErrors::InternalServerError)
|
||||
.attach_printable("Error Converting Struct To Serde Value")?;
|
||||
|
||||
@ -187,7 +183,7 @@ where
|
||||
{
|
||||
data.map(|metadata| serde_json::from_value(metadata.data_value.clone()))
|
||||
.transpose()
|
||||
.map_err(|_| UserErrors::InternalServerError.into())
|
||||
.change_context(UserErrors::InternalServerError)
|
||||
.attach_printable("Error Serializing Metadata from DB")
|
||||
}
|
||||
|
||||
@ -248,10 +244,10 @@ pub fn set_ip_address_if_required(
|
||||
if let SetMetaDataRequest::ProductionAgreement(req) = request {
|
||||
let ip_address_from_request: Secret<String, common_utils::pii::IpAddress> = headers
|
||||
.get(headers::X_FORWARDED_FOR)
|
||||
.ok_or(UserErrors::IpAddressParsingFailed.into())
|
||||
.ok_or(report!(UserErrors::IpAddressParsingFailed))
|
||||
.attach_printable("X-Forwarded-For header not found")?
|
||||
.to_str()
|
||||
.map_err(|_| UserErrors::IpAddressParsingFailed.into())
|
||||
.change_context(UserErrors::IpAddressParsingFailed)
|
||||
.attach_printable("Error converting Header Value to Str")?
|
||||
.split(',')
|
||||
.next()
|
||||
@ -259,7 +255,7 @@ pub fn set_ip_address_if_required(
|
||||
let ip_addr: Result<IpAddr, _> = ip.parse();
|
||||
ip_addr.ok()
|
||||
})
|
||||
.ok_or(UserErrors::IpAddressParsingFailed.into())
|
||||
.ok_or(report!(UserErrors::IpAddressParsingFailed))
|
||||
.attach_printable("Error Parsing header value to ip")?
|
||||
.to_string()
|
||||
.into();
|
||||
@ -274,7 +270,7 @@ pub fn parse_string_to_enums(query: String) -> UserResult<GetMultipleMetaDataPay
|
||||
.split(',')
|
||||
.map(GetMetaDataRequest::from_str)
|
||||
.collect::<Result<Vec<GetMetaDataRequest>, _>>()
|
||||
.map_err(|_| UserErrors::InvalidMetadataRequest.into())
|
||||
.change_context(UserErrors::InvalidMetadataRequest)
|
||||
.attach_printable("Error Parsing to DashboardMetadata enums")?,
|
||||
})
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ use argon2::{
|
||||
Argon2,
|
||||
};
|
||||
use common_utils::errors::CustomResult;
|
||||
use error_stack::{IntoReport, ResultExt};
|
||||
use error_stack::ResultExt;
|
||||
use masking::{ExposeInterface, Secret};
|
||||
|
||||
use crate::core::errors::UserErrors;
|
||||
@ -19,7 +19,6 @@ pub fn generate_password_hash(
|
||||
let argon2 = Argon2::default();
|
||||
let password_hash = argon2
|
||||
.hash_password(password.expose().as_bytes(), &salt)
|
||||
.into_report()
|
||||
.change_context(UserErrors::InternalServerError)?;
|
||||
Ok(Secret::new(password_hash.to_string()))
|
||||
}
|
||||
@ -29,15 +28,13 @@ pub fn is_correct_password(
|
||||
password: Secret<String>,
|
||||
) -> CustomResult<bool, UserErrors> {
|
||||
let password = password.expose();
|
||||
let parsed_hash = PasswordHash::new(&password)
|
||||
.into_report()
|
||||
.change_context(UserErrors::InternalServerError)?;
|
||||
let parsed_hash =
|
||||
PasswordHash::new(&password).change_context(UserErrors::InternalServerError)?;
|
||||
let result = Argon2::default().verify_password(candidate.expose().as_bytes(), &parsed_hash);
|
||||
match result {
|
||||
Ok(_) => Ok(true),
|
||||
Err(argon2Err::Password) => Ok(false),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
.into_report()
|
||||
.change_context(UserErrors::InternalServerError)
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ use api_models::{
|
||||
};
|
||||
use data_models::payments::payment_intent::PaymentIntentNew;
|
||||
use diesel_models::{user::sample_data::PaymentAttemptBatchNew, RefundNew};
|
||||
use error_stack::{IntoReport, ResultExt};
|
||||
use error_stack::ResultExt;
|
||||
use rand::{prelude::SliceRandom, thread_rng, Rng};
|
||||
use time::OffsetDateTime;
|
||||
|
||||
@ -44,7 +44,6 @@ pub async fn generate_sample_data(
|
||||
|
||||
let merchant_parsed_details: Vec<api_models::admin::PrimaryBusinessDetails> =
|
||||
serde_json::from_value(merchant_from_db.primary_business_details.clone())
|
||||
.into_report()
|
||||
.change_context(SampleDataError::InternalServerError)
|
||||
.attach_printable("Error while parsing primary business details")?;
|
||||
|
||||
@ -84,7 +83,6 @@ pub async fn generate_sample_data(
|
||||
// 10 percent payments should be failed
|
||||
#[allow(clippy::as_conversions)]
|
||||
let failure_attempts = usize::try_from((sample_data_size as f32 / 10.0).round() as i64)
|
||||
.into_report()
|
||||
.change_context(SampleDataError::InvalidParameters)?;
|
||||
|
||||
let failure_after_attempts = sample_data_size / failure_attempts;
|
||||
@ -92,7 +90,6 @@ pub async fn generate_sample_data(
|
||||
// 20 percent refunds for payments
|
||||
#[allow(clippy::as_conversions)]
|
||||
let number_of_refunds = usize::try_from((sample_data_size as f32 / 5.0).round() as i64)
|
||||
.into_report()
|
||||
.change_context(SampleDataError::InvalidParameters)?;
|
||||
|
||||
let mut refunds_count = 0;
|
||||
|
||||
@ -3,7 +3,7 @@ use std::collections::HashSet;
|
||||
use api_models::user_role as user_role_api;
|
||||
use common_enums::PermissionGroup;
|
||||
use diesel_models::user_role::UserRole;
|
||||
use error_stack::{IntoReport, ResultExt};
|
||||
use error_stack::{report, ResultExt};
|
||||
use router_env::logger;
|
||||
|
||||
use crate::{
|
||||
@ -52,19 +52,19 @@ impl From<Permission> for user_role_api::Permission {
|
||||
|
||||
pub fn validate_role_groups(groups: &[PermissionGroup]) -> UserResult<()> {
|
||||
if groups.is_empty() {
|
||||
return Err(UserErrors::InvalidRoleOperation.into())
|
||||
return Err(report!(UserErrors::InvalidRoleOperation))
|
||||
.attach_printable("Role groups cannot be empty");
|
||||
}
|
||||
|
||||
let unique_groups: HashSet<_> = groups.iter().cloned().collect();
|
||||
|
||||
if unique_groups.contains(&PermissionGroup::OrganizationManage) {
|
||||
return Err(UserErrors::InvalidRoleOperation.into())
|
||||
return Err(report!(UserErrors::InvalidRoleOperation))
|
||||
.attach_printable("Organization manage group cannot be added to role");
|
||||
}
|
||||
|
||||
if unique_groups.len() != groups.len() {
|
||||
return Err(UserErrors::InvalidRoleOperation.into())
|
||||
return Err(report!(UserErrors::InvalidRoleOperation))
|
||||
.attach_printable("Duplicate permission group found");
|
||||
}
|
||||
|
||||
@ -133,9 +133,7 @@ pub async fn set_role_permissions_in_cache_if_required(
|
||||
state,
|
||||
role_id,
|
||||
&role_info.get_permissions_set().into_iter().collect(),
|
||||
consts::JWT_TOKEN_TIME_IN_SECS
|
||||
.try_into()
|
||||
.into_report()
|
||||
i64::try_from(consts::JWT_TOKEN_TIME_IN_SECS)
|
||||
.change_context(UserErrors::InternalServerError)?,
|
||||
)
|
||||
.await
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use api_models::enums::Connector;
|
||||
use error_stack::{IntoReport, ResultExt};
|
||||
use error_stack::ResultExt;
|
||||
|
||||
use crate::{core::errors, types::api};
|
||||
|
||||
@ -11,8 +11,7 @@ pub fn generate_card_from_details(
|
||||
) -> errors::RouterResult<api::Card> {
|
||||
Ok(api::Card {
|
||||
card_number: card_number
|
||||
.parse()
|
||||
.into_report()
|
||||
.parse::<cards::CardNumber>()
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("Error while parsing card number")?,
|
||||
card_issuer: None,
|
||||
|
||||
Reference in New Issue
Block a user