mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +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(),
|
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 {}
|
impl api::Payment for Aci {}
|
||||||
@ -198,23 +225,7 @@ impl
|
|||||||
&self,
|
&self,
|
||||||
res: types::Response,
|
res: types::Response,
|
||||||
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
||||||
let response: aci::AciPaymentsResponse =
|
self.build_error_response(res)
|
||||||
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,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,23 +331,7 @@ impl
|
|||||||
&self,
|
&self,
|
||||||
res: types::Response,
|
res: types::Response,
|
||||||
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
||||||
let response: aci::AciPaymentsResponse =
|
self.build_error_response(res)
|
||||||
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
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -425,23 +420,7 @@ impl
|
|||||||
&self,
|
&self,
|
||||||
res: types::Response,
|
res: types::Response,
|
||||||
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
||||||
let response: aci::AciPaymentsResponse =
|
self.build_error_response(res)
|
||||||
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
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -536,23 +515,7 @@ impl services::ConnectorIntegration<api::Execute, types::RefundsData, types::Ref
|
|||||||
&self,
|
&self,
|
||||||
res: types::Response,
|
res: types::Response,
|
||||||
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {
|
||||||
let response: aci::AciRefundResponse = res
|
self.build_error_response(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
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -598,6 +598,15 @@ pub struct AciPaymentsResponse {
|
|||||||
pub(super) redirect: Option<AciRedirectionData>,
|
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)]
|
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct AciRedirectionData {
|
pub struct AciRedirectionData {
|
||||||
|
|||||||
Reference in New Issue
Block a user