Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(connector): [Klarna] Handle error response with both error_messages and error_message fields (#1783)
Arjun Karthik9cfdce0abe8a
diff --git a/crates/router/src/connector/klarna.rs b/crates/router/src/connector/klarna.rsindex 73d6f17248..4f15fb77db 100644--- a/crates/router/src/connector/klarna.rs+++ b/crates/router/src/connector/klarna.rs@@ -8,6 +8,7 @@ use transformers as klarna;use crate::{configs::settings,connector::utils as connector_utils,+ consts,core::errors::{self, CustomResult},headers,services::{@@ -50,6 +51,27 @@ impl ConnectorCommon for Klarna {auth.basic_token.into_masked(),)])}++ fn build_error_response(+ &self,+ res: types::Response,+ ) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {+ let response: klarna::KlarnaErrorResponse = res+ .response+ .parse_struct("KlarnaErrorResponse")+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;+ // KlarnaErrorResponse will either have error_messages or error_message field Ref: https://docs.klarna.com/api/errors/+ let reason = response+ .error_messages+ .map(|messages| messages.join(" & "))+ .or(response.error_message);+ Ok(types::ErrorResponse {+ status_code: res.status_code,+ code: response.error_code,+ message: consts::NO_ERROR_MESSAGE.to_string(),+ reason,+ })+ }}impl api::Payment for Klarna {}@@ -174,16 +196,7 @@ impl&self,res: types::Response,) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {- let response: klarna::KlarnaErrorResponse = res- .response- .parse_struct("KlarnaErrorResponse")- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;- Ok(types::ErrorResponse {- status_code: res.status_code,- code: response.error_code,- message: response.error_messages.join(" & "),- reason: None,- })+ self.build_error_response(res)}}@@ -338,16 +351,7 @@ impl&self,res: types::Response,) -> CustomResult<types::ErrorResponse, errors::ConnectorError> {- let response: klarna::KlarnaErrorResponse = res- .response- .parse_struct("KlarnaErrorResponse")- .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;- Ok(types::ErrorResponse {- status_code: res.status_code,- code: response.error_code,- message: response.error_messages.join(" & "),- reason: None,- })+ self.build_error_response(res)}}diff --git a/crates/router/src/connector/klarna/transformers.rs b/crates/router/src/connector/klarna/transformers.rsindex f2f839e751..3607818353 100644--- a/crates/router/src/connector/klarna/transformers.rs+++ b/crates/router/src/connector/klarna/transformers.rs@@ -189,5 +189,6 @@ impl From<KlarnaFraudStatus> for enums::AttemptStatus {#[derive(Deserialize)]pub struct KlarnaErrorResponse {pub error_code: String,- pub error_messages: Vec<String>,+ pub error_messages: Option<Vec<String>>,+ pub error_message: Option<String>,}