mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 03:13:56 +08:00
feat: add GenericNotFoundError error response and set_key_if_not_exists_with_expiry Redis command (#1526)
This commit is contained in:
@ -16,7 +16,7 @@ pub async fn is_stream_available(stream_index: u8, store: Arc<services::Store>)
|
||||
|
||||
match store
|
||||
.redis_conn
|
||||
.set_key_if_not_exist(stream_key_flag.as_str(), true)
|
||||
.set_key_if_not_exists_with_expiry(stream_key_flag.as_str(), true, None)
|
||||
.await
|
||||
{
|
||||
Ok(resp) => resp == redis::types::SetnxReply::KeySet,
|
||||
|
||||
@ -175,10 +175,11 @@ impl super::RedisConnectionPool {
|
||||
}
|
||||
|
||||
#[instrument(level = "DEBUG", skip(self))]
|
||||
pub async fn set_key_if_not_exist<V>(
|
||||
pub async fn set_key_if_not_exists_with_expiry<V>(
|
||||
&self,
|
||||
key: &str,
|
||||
value: V,
|
||||
seconds: Option<i64>,
|
||||
) -> CustomResult<SetnxReply, errors::RedisError>
|
||||
where
|
||||
V: TryInto<RedisValue> + Debug + Send + Sync,
|
||||
@ -188,9 +189,11 @@ impl super::RedisConnectionPool {
|
||||
.set(
|
||||
key,
|
||||
value,
|
||||
Some(Expiration::EX(self.config.default_ttl.into())),
|
||||
Some(Expiration::EX(
|
||||
seconds.unwrap_or(self.config.default_ttl.into()),
|
||||
)),
|
||||
Some(SetOptions::NX),
|
||||
false,
|
||||
true,
|
||||
)
|
||||
.await
|
||||
.into_report()
|
||||
|
||||
@ -82,6 +82,9 @@ pub enum StripeErrorCode {
|
||||
#[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "No such payment method")]
|
||||
PaymentMethodNotFound,
|
||||
|
||||
#[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "{message}")]
|
||||
GenericNotFoundError { message: String },
|
||||
|
||||
#[error(error_type = StripeErrorType::InvalidRequestError, code = "resource_missing", message = "No such merchant account")]
|
||||
MerchantAccountNotFound,
|
||||
|
||||
@ -391,6 +394,9 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
|
||||
param: field_names.clone().join(", "),
|
||||
}
|
||||
}
|
||||
errors::ApiErrorResponse::GenericNotFoundError { message } => {
|
||||
Self::GenericNotFoundError { message }
|
||||
}
|
||||
// parameter unknown, invalid request error // actually if we type wrong values in address we get this error. Stripe throws parameter unknown. I don't know if stripe is validating email and stuff
|
||||
errors::ApiErrorResponse::InvalidDataFormat {
|
||||
field_name,
|
||||
@ -535,7 +541,7 @@ impl actix_web::ResponseError for StripeErrorCode {
|
||||
|
||||
match self {
|
||||
Self::Unauthorized => StatusCode::UNAUTHORIZED,
|
||||
Self::InvalidRequestUrl => StatusCode::NOT_FOUND,
|
||||
Self::InvalidRequestUrl | Self::GenericNotFoundError { .. } => StatusCode::NOT_FOUND,
|
||||
Self::ParameterUnknown { .. } | Self::HyperswitchUnprocessableEntity { .. } => {
|
||||
StatusCode::UNPROCESSABLE_ENTITY
|
||||
}
|
||||
|
||||
@ -196,6 +196,8 @@ pub enum ApiErrorResponse {
|
||||
MissingFilePurpose,
|
||||
#[error(error_type = ErrorType::InvalidRequestError, code = "HE_04", message = "File content type not found / valid")]
|
||||
MissingFileContentType,
|
||||
#[error(error_type = ErrorType::InvalidRequestError, code = "HE_05", message = "{message}")]
|
||||
GenericNotFoundError { message: String },
|
||||
#[error(error_type = ErrorType::InvalidRequestError, code = "WE_01", message = "Failed to authenticate the webhook")]
|
||||
WebhookAuthenticationFailed,
|
||||
#[error(error_type = ErrorType::ObjectNotFound, code = "WE_04", message = "Webhook resource not found")]
|
||||
@ -433,6 +435,9 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorRespon
|
||||
Self::AddressNotFound => {
|
||||
AER::NotFound(ApiError::new("HE", 4, "Address does not exist in our records", None))
|
||||
},
|
||||
Self::GenericNotFoundError { message } => {
|
||||
AER::NotFound(ApiError::new("HE", 5, message, None))
|
||||
},
|
||||
Self::ApiKeyNotFound => {
|
||||
AER::NotFound(ApiError::new("HE", 2, "API Key does not exist in our records", None))
|
||||
}
|
||||
|
||||
@ -83,7 +83,9 @@ impl QueueInterface for Store {
|
||||
ttl: i64,
|
||||
) -> CustomResult<bool, RedisError> {
|
||||
let conn = self.redis_conn()?.clone();
|
||||
let is_lock_acquired = conn.set_key_if_not_exist(lock_key, lock_val).await;
|
||||
let is_lock_acquired = conn
|
||||
.set_key_if_not_exists_with_expiry(lock_key, lock_val, None)
|
||||
.await;
|
||||
Ok(match is_lock_acquired {
|
||||
Ok(SetnxReply::KeySet) => match conn.set_expiry(lock_key, ttl).await {
|
||||
Ok(()) => true,
|
||||
|
||||
Reference in New Issue
Block a user