Skip to content

Commit

Permalink
fix: handle unique constraint violation error gracefully (#1202)
Browse files Browse the repository at this point in the history
  • Loading branch information
manoj-juspay authored May 18, 2023
1 parent 2d49ce5 commit b3fd174
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions crates/router/src/core/payment_methods/vault.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use common_utils::generate_id_with_default_len;
#[cfg(feature = "basilisk")]
use error_stack::report;
use error_stack::{IntoReport, ResultExt};
#[cfg(feature = "basilisk")]
use external_services::kms;
Expand Down Expand Up @@ -648,7 +650,7 @@ pub async fn add_delete_tokenized_data_task(
db: &dyn db::StorageInterface,
lookup_key: &str,
pm: enums::PaymentMethod,
) -> RouterResult<storage::ProcessTracker> {
) -> RouterResult<()> {
let runner = "DELETE_TOKENIZE_DATA_WORKFLOW";
let current_time = common_utils::date_time::now();
let tracking_data = serde_json::to_value(storage::TokenizeCoreWorkflow {
Expand Down Expand Up @@ -676,14 +678,14 @@ pub async fn add_delete_tokenized_data_task(
created_at: current_time,
updated_at: current_time,
};
let response = db
.insert_process(process_tracker_entry)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable_lazy(|| {
format!("Failed while inserting task in process_tracker: lookup_key: {lookup_key}")
})?;
Ok(response)
let response = db.insert_process(process_tracker_entry).await;
response.map(|_| ()).or_else(|err| {
if err.current_context().is_db_unique_violation() {
Ok(())
} else {
Err(report!(errors::ApiErrorResponse::InternalServerError))
}
})
}

#[cfg(feature = "basilisk")]
Expand Down

0 comments on commit b3fd174

Please sign in to comment.