refactor(router): return generic message for UnprocessableEntity in make_pm_data (#2050)

This commit is contained in:
Shankar Singh C
2023-09-01 13:52:22 +05:30
committed by GitHub
parent e730c73516
commit 38ab6e54f1
5 changed files with 342 additions and 78 deletions

View File

@ -1860,11 +1860,7 @@ pub async fn list_customer_payment_method(
consts::TOKEN_TTL - time_elapsed.whole_seconds(),
)
.await
.map_err(|error| {
logger::error!(connector_payment_method_token_kv_error=?error);
errors::StorageError::KVError
})
.into_report()
.change_context(errors::StorageError::KVError)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to add data in redis")?;
}

View File

@ -1203,7 +1203,7 @@ pub async fn make_pm_data<'a, F: Clone, R>(
.attach_printable("Failed to fetch the token from redis")?
.ok_or(error_stack::Report::new(
errors::ApiErrorResponse::UnprocessableEntity {
message: token + " is invalid or expired",
message: "Token is invalid or expired".to_owned(),
},
))?;

View File

@ -11,7 +11,6 @@ use super::{MockDb, Store};
use crate::{
connection,
core::errors::{self, CustomResult},
services::logger,
types::{
self,
domain::{
@ -80,11 +79,7 @@ impl ConnectorAccessToken for Store {
.map_err(Into::<errors::StorageError>::into)?
.set_key_with_expiry(&key, serialized_access_token, access_token.expires)
.await
.map_err(|error| {
logger::error!(access_token_kv_error=?error);
errors::StorageError::KVError
})
.into_report()
.change_context(errors::StorageError::KVError)
}
}

View File

@ -1,6 +1,6 @@
use actix_web::{web, HttpRequest, HttpResponse};
use common_utils::{consts::TOKEN_TTL, errors::CustomResult};
use error_stack::{IntoReport, ResultExt};
use error_stack::ResultExt;
use router_env::{instrument, logger, tracing, Flow};
use time::PrimitiveDateTime;
@ -397,13 +397,9 @@ impl ParentPaymentMethodToken {
TOKEN_TTL - time_elapsed.whole_seconds(),
)
.await
.map_err(|error| {
logger::error!(hyperswitch_token_kv_error=?error);
errors::StorageError::KVError
})
.into_report()
.change_context(errors::StorageError::KVError)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to add data in redis")?;
.attach_printable("Failed to add token in redis")?;
Ok(())
}