mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	feat: add GenericNotFoundError error response and set_key_if_not_exists_with_expiry Redis command (#1526)
				
					
				
			This commit is contained in:
		| @ -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
	 Prajjwal Kumar
					Prajjwal Kumar