Skip to content

Commit

Permalink
fix(connector): [Powertranz] Fix response handling for https status c…
Browse files Browse the repository at this point in the history
…ode other than 200 (#1775)
  • Loading branch information
ArjunKarthik authored Jul 26, 2023
1 parent d068569 commit 4805a94
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions crates/router/src/connector/powertranz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,13 @@ impl ConnectorCommon for Powertranz {
&self,
res: Response,
) -> CustomResult<ErrorResponse, errors::ConnectorError> {
let response: powertranz::PowertranzErrorResponse = res
.response
.parse_struct("PowertranzErrorResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
let first_error = response.errors.first();
let code = first_error.map(|error| error.code.clone());
let message = first_error.map(|error| error.message.clone());

// For error scenerios connector respond with 200 http status code and error response object in response
// For http status code other than 200 they send empty response back
Ok(ErrorResponse {
status_code: res.status_code,
code: code.unwrap_or_else(|| consts::NO_ERROR_CODE.to_string()),
message: message.unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()),
reason: Some(
response
.errors
.iter()
.map(|error| format!("{} : {}", error.code, error.message))
.collect::<Vec<_>>()
.join(", "),
),
code: consts::NO_ERROR_CODE.to_string(),
message: consts::NO_ERROR_MESSAGE.to_string(),
reason: None,
})
}
}
Expand Down

0 comments on commit 4805a94

Please sign in to comment.