Skip to content

Commit

Permalink
refactor(connector): [itau] refactor error reason and code mapping fo…
Browse files Browse the repository at this point in the history
…r itau (#5718)

Co-authored-by: Chikke Srujan <chikke.srujan@Chikke-Srujan-N7WRTY72X7.local>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 28, 2024
1 parent 9e28572 commit f024ffb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
36 changes: 30 additions & 6 deletions crates/router/src/connector/itaubank.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pub mod transformers;

use std::fmt::Write;

use common_utils::types::{AmountConvertor, StringMajorUnit, StringMajorUnitForConnector};
use error_stack::{report, ResultExt};
use hyperswitch_interfaces::consts;
Expand Down Expand Up @@ -125,14 +127,34 @@ impl ConnectorCommon for Itaubank {
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);

let reason = response
.error
.violacoes
.map(|violacoes| {
violacoes.iter().try_fold(String::new(), |mut acc, error| {
write!(
acc,
" razao - {}, propriedade - {}, valor - {};",
error.razao, error.propriedade, error.valor
)
.change_context(errors::ConnectorError::ResponseDeserializationFailed)
.attach_printable("Failed to concatenate error details")
.map(|_| acc)
})
})
.transpose()?;

Ok(ErrorResponse {
status_code: res.status_code,
code: response.error.status.to_string(),
message: response
code: response
.error
.title
.unwrap_or(consts::NO_ERROR_CODE.to_string()),
message: response
.error
.detail
.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
reason: response.error.detail,
reason,
attempt_status: None,
connector_transaction_id: None,
})
Expand Down Expand Up @@ -251,11 +273,13 @@ impl ConnectorIntegration<api::AccessTokenAuth, types::AccessTokenRequestData, t

Ok(ErrorResponse {
status_code: res.status_code,
code: response.status.to_string(),
code: response.title.unwrap_or(consts::NO_ERROR_CODE.to_string()),
message: response
.title
.detail
.to_owned()
.or(response.user_message.to_owned())
.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
reason: response.detail,
reason: response.detail.or(response.user_message),
attempt_status: None,
connector_transaction_id: None,
})
Expand Down
10 changes: 10 additions & 0 deletions crates/router/src/connector/itaubank/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,12 @@ pub struct ItaubankUpdateTokenResponse {
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ItaubankTokenErrorResponse {
pub status: i64,
pub title: Option<String>,
pub detail: Option<String>,
pub user_message: Option<String>,
}

impl<F, T> TryFrom<types::ResponseRouterData<F, ItaubankUpdateTokenResponse, T, types::AccessToken>>
Expand Down Expand Up @@ -464,4 +466,12 @@ pub struct ItaubankErrorBody {
pub status: u16,
pub title: Option<String>,
pub detail: Option<String>,
pub violacoes: Option<Vec<Violations>>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Violations {
pub razao: String,
pub propriedade: String,
pub valor: String,
}

0 comments on commit f024ffb

Please # to comment.