mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 09:38:33 +08:00
feat(router): send 2xx payments response for all the connector http responses (2xx, 4xx etc.) (#1924)
This commit is contained in:
committed by
GitHub
parent
35963e279a
commit
0ab6827f6c
@ -365,3 +365,45 @@ pub fn handle_json_response_deserialization_failure(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_http_status_code_type(
|
||||
status_code: u16,
|
||||
) -> CustomResult<String, errors::ApiErrorResponse> {
|
||||
let status_code_type = match status_code {
|
||||
100..=199 => "1xx",
|
||||
200..=299 => "2xx",
|
||||
300..=399 => "3xx",
|
||||
400..=499 => "4xx",
|
||||
500..=599 => "5xx",
|
||||
_ => Err(errors::ApiErrorResponse::InternalServerError)
|
||||
.into_report()
|
||||
.attach_printable("Invalid http status code")?,
|
||||
};
|
||||
Ok(status_code_type.to_string())
|
||||
}
|
||||
|
||||
pub fn add_connector_http_status_code_metrics(option_status_code: Option<u16>) {
|
||||
if let Some(status_code) = option_status_code {
|
||||
let status_code_type = get_http_status_code_type(status_code).ok();
|
||||
match status_code_type.as_deref() {
|
||||
Some("1xx") => {
|
||||
metrics::CONNECTOR_HTTP_STATUS_CODE_1XX_COUNT.add(&metrics::CONTEXT, 1, &[])
|
||||
}
|
||||
Some("2xx") => {
|
||||
metrics::CONNECTOR_HTTP_STATUS_CODE_2XX_COUNT.add(&metrics::CONTEXT, 1, &[])
|
||||
}
|
||||
Some("3xx") => {
|
||||
metrics::CONNECTOR_HTTP_STATUS_CODE_3XX_COUNT.add(&metrics::CONTEXT, 1, &[])
|
||||
}
|
||||
Some("4xx") => {
|
||||
metrics::CONNECTOR_HTTP_STATUS_CODE_4XX_COUNT.add(&metrics::CONTEXT, 1, &[])
|
||||
}
|
||||
Some("5xx") => {
|
||||
metrics::CONNECTOR_HTTP_STATUS_CODE_5XX_COUNT.add(&metrics::CONTEXT, 1, &[])
|
||||
}
|
||||
_ => logger::info!("Skip metrics as invalid http status code received from connector"),
|
||||
};
|
||||
} else {
|
||||
logger::info!("Skip metrics as no http status code received from connector")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user