refactor(router): add id field in MerchantConnectorAccountNotFound (#1098)

This commit is contained in:
EliKalter
2023-05-10 14:56:45 +03:00
committed by GitHub
parent c5db5c37ec
commit 5214e22f20
4 changed files with 26 additions and 16 deletions

View File

@ -88,8 +88,8 @@ pub enum StripeErrorCode {
#[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "No such resource ID")] #[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "No such resource ID")]
ResourceIdNotFound, ResourceIdNotFound,
#[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "No such merchant connector account")] #[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "Merchant connector account with id '{id}' does not exist in our records")]
MerchantConnectorAccountNotFound, MerchantConnectorAccountNotFound { id: String },
#[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "No such mandate")] #[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "No such mandate")]
MandateNotFound, MandateNotFound,
@ -429,8 +429,8 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
| errors::ApiErrorResponse::ClientSecretExpired => Self::ClientSecretNotFound, | errors::ApiErrorResponse::ClientSecretExpired => Self::ClientSecretNotFound,
errors::ApiErrorResponse::MerchantAccountNotFound => Self::MerchantAccountNotFound, errors::ApiErrorResponse::MerchantAccountNotFound => Self::MerchantAccountNotFound,
errors::ApiErrorResponse::ResourceIdNotFound => Self::ResourceIdNotFound, errors::ApiErrorResponse::ResourceIdNotFound => Self::ResourceIdNotFound,
errors::ApiErrorResponse::MerchantConnectorAccountNotFound => { errors::ApiErrorResponse::MerchantConnectorAccountNotFound { id } => {
Self::MerchantConnectorAccountNotFound Self::MerchantConnectorAccountNotFound { id }
} }
errors::ApiErrorResponse::MandateNotFound => Self::MandateNotFound, errors::ApiErrorResponse::MandateNotFound => Self::MandateNotFound,
errors::ApiErrorResponse::ApiKeyNotFound => Self::ApiKeyNotFound, errors::ApiErrorResponse::ApiKeyNotFound => Self::ApiKeyNotFound,
@ -518,7 +518,7 @@ impl actix_web::ResponseError for StripeErrorCode {
| Self::PaymentNotFound | Self::PaymentNotFound
| Self::PaymentMethodNotFound | Self::PaymentMethodNotFound
| Self::MerchantAccountNotFound | Self::MerchantAccountNotFound
| Self::MerchantConnectorAccountNotFound | Self::MerchantConnectorAccountNotFound { .. }
| Self::MandateNotFound | Self::MandateNotFound
| Self::ApiKeyNotFound | Self::ApiKeyNotFound
| Self::DuplicateMerchantAccount | Self::DuplicateMerchantAccount

View File

@ -449,7 +449,9 @@ pub async fn retrieve_payment_connector(
&merchant_connector_id, &merchant_connector_id,
) )
.await .await
.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)?; .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
id: merchant_connector_id.clone(),
})?;
Ok(service_api::ApplicationResponse::Json( Ok(service_api::ApplicationResponse::Json(
ForeignTryFrom::foreign_try_from(mca)?, ForeignTryFrom::foreign_try_from(mca)?,
@ -469,7 +471,7 @@ pub async fn list_payment_connectors(
let merchant_connector_accounts = store let merchant_connector_accounts = store
.find_merchant_connector_account_by_merchant_id_and_disabled_list(&merchant_id, true) .find_merchant_connector_account_by_merchant_id_and_disabled_list(&merchant_id, true)
.await .await
.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)?; .to_not_found_response(errors::ApiErrorResponse::InternalServerError)?;
let mut response = vec![]; let mut response = vec![];
// The can be eliminated once [#79711](https://github.com/rust-lang/rust/issues/79711) is stabilized // The can be eliminated once [#79711](https://github.com/rust-lang/rust/issues/79711) is stabilized
@ -497,7 +499,9 @@ pub async fn update_payment_connector(
merchant_connector_id, merchant_connector_id,
) )
.await .await
.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)?; .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
id: merchant_connector_id.to_string(),
})?;
let payment_methods_enabled = req.payment_methods_enabled.map(|pm_enabled| { let payment_methods_enabled = req.payment_methods_enabled.map(|pm_enabled| {
pm_enabled pm_enabled
@ -557,7 +561,9 @@ pub async fn delete_payment_connector(
&merchant_connector_id, &merchant_connector_id,
) )
.await .await
.to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound)?; .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
id: merchant_connector_id.clone(),
})?;
let response = api::MerchantConnectorDeleteResponse { let response = api::MerchantConnectorDeleteResponse {
merchant_id, merchant_id,
merchant_connector_id, merchant_connector_id,

View File

@ -136,8 +136,8 @@ pub enum ApiErrorResponse {
PaymentMethodNotFound, PaymentMethodNotFound,
#[error(error_type = ErrorType::ObjectNotFound, code = "HE_02", message = "Merchant account does not exist in our records")] #[error(error_type = ErrorType::ObjectNotFound, code = "HE_02", message = "Merchant account does not exist in our records")]
MerchantAccountNotFound, MerchantAccountNotFound,
#[error(error_type = ErrorType::ObjectNotFound, code = "HE_02", message = "Merchant connector account does not exist in our records")] #[error(error_type = ErrorType::ObjectNotFound, code = "HE_02", message = "Merchant connector account with id '{id}' does not exist in our records")]
MerchantConnectorAccountNotFound, MerchantConnectorAccountNotFound { id: String },
#[error(error_type = ErrorType::ObjectNotFound, code = "HE_02", message = "Resource ID does not exist in our records")] #[error(error_type = ErrorType::ObjectNotFound, code = "HE_02", message = "Resource ID does not exist in our records")]
ResourceIdNotFound, ResourceIdNotFound,
#[error(error_type = ErrorType::ObjectNotFound, code = "HE_02", message = "Mandate does not exist in our records")] #[error(error_type = ErrorType::ObjectNotFound, code = "HE_02", message = "Mandate does not exist in our records")]
@ -259,7 +259,7 @@ impl actix_web::ResponseError for ApiErrorResponse {
| Self::PaymentNotFound | Self::PaymentNotFound
| Self::PaymentMethodNotFound | Self::PaymentMethodNotFound
| Self::MerchantAccountNotFound | Self::MerchantAccountNotFound
| Self::MerchantConnectorAccountNotFound | Self::MerchantConnectorAccountNotFound { .. }
| Self::MandateNotFound | Self::MandateNotFound
| Self::ClientSecretNotGiven | Self::ClientSecretNotGiven
| Self::ClientSecretExpired | Self::ClientSecretExpired
@ -438,8 +438,8 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorRespon
Self::MerchantAccountNotFound => { Self::MerchantAccountNotFound => {
AER::NotFound(ApiError::new("HE", 2, "Merchant account does not exist in our records", None)) AER::NotFound(ApiError::new("HE", 2, "Merchant account does not exist in our records", None))
} }
Self::MerchantConnectorAccountNotFound => { Self::MerchantConnectorAccountNotFound { id } => {
AER::NotFound(ApiError::new("HE", 2, "Merchant connector account does not exist in our records", None)) AER::NotFound(ApiError::new("HE", 2, format!("Merchant connector account with id '{id}' does not exist in our records"), None))
} }
Self::ResourceIdNotFound => { Self::ResourceIdNotFound => {
AER::NotFound(ApiError::new("HE", 2, "Resource ID does not exist in our records", None)) AER::NotFound(ApiError::new("HE", 2, "Resource ID does not exist in our records", None))

View File

@ -1565,7 +1565,9 @@ pub async fn get_merchant_connector_account(
.find_config_by_key(format!("mcd_{merchant_id}_{creds_identifier}").as_str()) .find_config_by_key(format!("mcd_{merchant_id}_{creds_identifier}").as_str())
.await .await
.to_not_found_response( .to_not_found_response(
errors::ApiErrorResponse::MerchantConnectorAccountNotFound, errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
id: connector_label.to_string(),
},
)?; )?;
#[cfg(feature = "kms")] #[cfg(feature = "kms")]
@ -1605,7 +1607,9 @@ pub async fn get_merchant_connector_account(
) )
.await .await
.map(MerchantConnectorAccountType::DbVal) .map(MerchantConnectorAccountType::DbVal)
.change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound), .change_context(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {
id: connector_label.to_string(),
}),
} }
} }