mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 00:49:42 +08:00
fix(connector): [ACI] Response Handling in case of ErrorResponse (#1870)
This commit is contained in:
@ -50,6 +50,33 @@ impl ConnectorCommon for Aci {
|
||||
auth.api_key.into_masked(),
|
||||
)])
|
||||
}
|
||||
|
||||
fn build_error_response(
|
||||
&self,
|
||||
res: types::Response,
|
||||
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
||||
let response: aci::AciErrorResponse = res
|
||||
.response
|
||||
.parse_struct("AciErrorResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
Ok(types::ErrorResponse {
|
||||
status_code: res.status_code,
|
||||
code: response.result.code,
|
||||
message: response.result.description,
|
||||
reason: response.result.parameter_errors.map(|errors| {
|
||||
errors
|
||||
.into_iter()
|
||||
.map(|error_description| {
|
||||
format!(
|
||||
"Field is {} and the message is {}",
|
||||
error_description.name, error_description.message
|
||||
)
|
||||
})
|
||||
.collect::<Vec<String>>()
|
||||
.join("; ")
|
||||
}),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl api::Payment for Aci {}
|
||||
@ -198,23 +225,7 @@ impl
|
||||
&self,
|
||||
res: types::Response,
|
||||
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
||||
let response: aci::AciPaymentsResponse =
|
||||
res.response
|
||||
.parse_struct("AciPaymentsResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
Ok(types::ErrorResponse {
|
||||
code: response.result.code,
|
||||
message: response.result.description,
|
||||
reason: response.result.parameter_errors.and_then(|errors| {
|
||||
errors.first().map(|error_description| {
|
||||
format!(
|
||||
"Field is {} and the message is {}",
|
||||
error_description.name, error_description.message
|
||||
)
|
||||
})
|
||||
}),
|
||||
status_code: res.status_code,
|
||||
})
|
||||
self.build_error_response(res)
|
||||
}
|
||||
}
|
||||
|
||||
@ -320,23 +331,7 @@ impl
|
||||
&self,
|
||||
res: types::Response,
|
||||
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
||||
let response: aci::AciPaymentsResponse =
|
||||
res.response
|
||||
.parse_struct("AciPaymentsResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
Ok(types::ErrorResponse {
|
||||
status_code: res.status_code,
|
||||
code: response.result.code,
|
||||
message: response.result.description,
|
||||
reason: response.result.parameter_errors.and_then(|errors| {
|
||||
errors.first().map(|error_description| {
|
||||
format!(
|
||||
"Field is {} and the message is {}",
|
||||
error_description.name, error_description.message
|
||||
)
|
||||
})
|
||||
}),
|
||||
})
|
||||
self.build_error_response(res)
|
||||
}
|
||||
}
|
||||
|
||||
@ -425,23 +420,7 @@ impl
|
||||
&self,
|
||||
res: types::Response,
|
||||
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
||||
let response: aci::AciPaymentsResponse =
|
||||
res.response
|
||||
.parse_struct("AciPaymentsResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
Ok(types::ErrorResponse {
|
||||
status_code: res.status_code,
|
||||
code: response.result.code,
|
||||
message: response.result.description,
|
||||
reason: response.result.parameter_errors.and_then(|errors| {
|
||||
errors.first().map(|error_description| {
|
||||
format!(
|
||||
"Field is {} and the message is {}",
|
||||
error_description.name, error_description.message
|
||||
)
|
||||
})
|
||||
}),
|
||||
})
|
||||
self.build_error_response(res)
|
||||
}
|
||||
}
|
||||
|
||||
@ -536,23 +515,7 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref
|
||||
&self,
|
||||
res: types::Response,
|
||||
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
||||
let response: aci::AciRefundResponse = res
|
||||
.response
|
||||
.parse_struct("AciRefundResponse")
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
Ok(types::ErrorResponse {
|
||||
status_code: res.status_code,
|
||||
code: response.result.code,
|
||||
message: response.result.description,
|
||||
reason: response.result.parameter_errors.and_then(|errors| {
|
||||
errors.first().map(|error_description| {
|
||||
format!(
|
||||
"Field is {} and the message is {}",
|
||||
error_description.name, error_description.message
|
||||
)
|
||||
})
|
||||
}),
|
||||
})
|
||||
self.build_error_response(res)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -598,6 +598,15 @@ pub struct AciPaymentsResponse {
|
||||
pub(super) redirect: Option<AciRedirectionData>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AciErrorResponse {
|
||||
ndc: String,
|
||||
timestamp: String,
|
||||
build_number: String,
|
||||
pub(super) result: ResultCode,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct AciRedirectionData {
|
||||
|
||||
Reference in New Issue
Block a user