From 2ebd6dc63472a996a075fd41b66a381d774d7cdf Mon Sep 17 00:00:00 2001 From: kasisnu <5044120+kasisnu@users.noreply.github.com> Date: Fri, 10 Nov 2023 15:05:02 +0530 Subject: [PATCH] fix various stripe handler errors :( --- .../customer_subscription_created_handler.rs | 25 +++++++++++-------- .../customer_subscription_deleted_handler.rs | 20 +++++++++------ .../customer_subscription_updated_handler.rs | 25 +++++++++++-------- .../invoice/invoice_paid_handler.rs | 5 ++-- 4 files changed, 45 insertions(+), 30 deletions(-) diff --git a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer_subscription/customer_subscription_created_handler.rs b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer_subscription/customer_subscription_created_handler.rs index e4536c0d1d..e792490c8d 100644 --- a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer_subscription/customer_subscription_created_handler.rs +++ b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer_subscription/customer_subscription_created_handler.rs @@ -25,8 +25,9 @@ pub async fn customer_subscription_created_handler( let summary = subscription_summary_extractor(subscription) .map_err(|err| { - error!("Error extracting subscription from 'customer.subscription.created' payload: {:?}", err); - StripeWebhookError::ServerError // NB: This was probably *our* fault. + let reason = format!("Error extracting subscription from 'customer.subscription.created' payload: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) // NB: This was probably *our* fault. })?; let mut result = StripeWebhookSummary { @@ -42,8 +43,9 @@ pub async fn customer_subscription_created_handler( let maybe_existing_subscription = get_user_subscription_by_stripe_subscription_id(&summary.stripe_subscription_id, &mysql_pool) .await .map_err(|err| { - error!("Mysql error: {:?}", err); - StripeWebhookError::ServerError + let reason = format!("Mysql error: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) })?; if maybe_existing_subscription.is_some() { @@ -54,8 +56,9 @@ pub async fn customer_subscription_created_handler( let maybe_internal_subscription_product = internal_subscription_product_lookup.lookup_internal_product_from_stripe_product_id(&summary.stripe_product_id) .map_err(|err| { - error!("Error mapping to internal product: {:?}", err); - StripeWebhookError::ServerError // NB: This was probably *our* fault. + let reason = format!("Error mapping to internal product: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) // NB: This was probably *our* fault. })?; let mut subscription_namespace = UNKNOWN_SUBSCRIPTION_NAMESPACE; @@ -91,8 +94,9 @@ pub async fn customer_subscription_created_handler( let _r = upsert.upsert(mysql_pool) .await .map_err(|err| { - error!("Mysql error: {:?}", err); - StripeWebhookError::ServerError + let reason = format!("Mysql error: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) })?; @@ -104,8 +108,9 @@ pub async fn customer_subscription_created_handler( Some(&summary.stripe_customer_id)) .await .map_err(|err| { - error!("Mysql error: {:?}", err); - StripeWebhookError::ServerError + let reason = format!("Mysql error: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) })?; result.action_was_taken = true; diff --git a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer_subscription/customer_subscription_deleted_handler.rs b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer_subscription/customer_subscription_deleted_handler.rs index fd70dae0a9..937c3d67c5 100644 --- a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer_subscription/customer_subscription_deleted_handler.rs +++ b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer_subscription/customer_subscription_deleted_handler.rs @@ -22,8 +22,9 @@ pub async fn customer_subscription_deleted_handler( ) -> Result { let summary = subscription_summary_extractor(subscription) .map_err(|err| { - error!("Error extracting subscription from 'customer.subscription.deleted' payload: {:?}", err); - StripeWebhookError::ServerError // NB: This was probably *our* fault. + let reason = format!("Error extracting subscription from 'customer.subscription.deleted' payload: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) // NB: This was probably *our* fault. })?; let mut should_process_update = true; @@ -34,8 +35,9 @@ pub async fn customer_subscription_deleted_handler( let maybe_internal_subscription_product = internal_subscription_product_lookup.lookup_internal_product_from_stripe_product_id(&summary.stripe_product_id) .map_err(|err| { - error!("Error mapping to internal product: {:?}", err); - StripeWebhookError::ServerError // NB: This was probably *our* fault. + let reason = format!("Error mapping to internal product: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) // NB: This was probably *our* fault. })?; let mut subscription_namespace = UNKNOWN_SUBSCRIPTION_NAMESPACE; @@ -50,8 +52,9 @@ pub async fn customer_subscription_deleted_handler( let maybe_existing_subscription = get_user_subscription_by_stripe_subscription_id(&summary.stripe_subscription_id, &mysql_pool) .await .map_err(|err| { - error!("Mysql error: {:?}", err); - StripeWebhookError::ServerError + let reason = format!("Mysql error: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) })?; if let Some(existing_subscription) = maybe_existing_subscription { @@ -92,8 +95,9 @@ pub async fn customer_subscription_deleted_handler( let _r = upsert.upsert(mysql_pool) .await .map_err(|err| { - error!("Mysql error: {:?}", err); - StripeWebhookError::ServerError + let reason = format!("Mysql error: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) })?; action_was_taken = true; diff --git a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer_subscription/customer_subscription_updated_handler.rs b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer_subscription/customer_subscription_updated_handler.rs index 55b1d36ae3..00f5aedc3d 100644 --- a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer_subscription/customer_subscription_updated_handler.rs +++ b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/customer_subscription/customer_subscription_updated_handler.rs @@ -23,8 +23,9 @@ pub async fn customer_subscription_updated_handler( let summary = subscription_summary_extractor(subscription) .map_err(|err| { - error!("Error extracting subscription from 'customer.subscription.updated' payload: {:?}", err); - StripeWebhookError::ServerError // NB: This was probably *our* fault. + let reason = format!("Error extracting subscription from 'customer.subscription.updated' payload: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) // NB: This was probably *our* fault. })?; let mut should_process_update = true; @@ -35,8 +36,9 @@ pub async fn customer_subscription_updated_handler( let maybe_internal_subscription_product = internal_subscription_product_lookup.lookup_internal_product_from_stripe_product_id(&summary.stripe_product_id) .map_err(|err| { - error!("Error mapping to internal product: {:?}", err); - StripeWebhookError::ServerError // NB: This was probably *our* fault. + let reason = format!("Error mapping to internal product: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) // NB: This was probably *our* fault. })?; let mut subscription_namespace = UNKNOWN_SUBSCRIPTION_NAMESPACE; @@ -51,8 +53,9 @@ pub async fn customer_subscription_updated_handler( let maybe_existing_subscription = get_user_subscription_by_stripe_subscription_id(&summary.stripe_subscription_id, &mysql_pool) .await .map_err(|err| { - error!("Mysql error: {:?}", err); - StripeWebhookError::ServerError + let reason = format!("Mysql error: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) })?; if let Some(existing_subscription) = maybe_existing_subscription { @@ -92,8 +95,9 @@ pub async fn customer_subscription_updated_handler( let _r = upsert.upsert(mysql_pool) .await .map_err(|err| { - error!("Mysql error: {:?}", err); - StripeWebhookError::ServerError + let reason = format!("Mysql error: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) })?; info!("Updating user record with stripe customer ID"); @@ -106,8 +110,9 @@ pub async fn customer_subscription_updated_handler( Some(&summary.stripe_customer_id)) .await .map_err(|err| { - error!("Mysql error: {:?}", err); - StripeWebhookError::ServerError + let reason = format!("Mysql error: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) })?; action_was_taken = true; diff --git a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/invoice/invoice_paid_handler.rs b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/invoice/invoice_paid_handler.rs index c70cd78d0f..e39788b897 100644 --- a/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/invoice/invoice_paid_handler.rs +++ b/crates/service/plugins/billing/src/stripe/http_endpoints/webhook/webhook_event_handlers/invoice/invoice_paid_handler.rs @@ -71,8 +71,9 @@ pub enum InvoicePaidDetails { pub fn invoice_paid_handler(invoice: &Invoice) -> Result { let maybe_invoice_details = invoice_paid_extractor(invoice) .map_err(|err| { - error!("Error processing invoice: {:?}", err); - StripeWebhookError::ServerError + let reason = format!("Error extracting invoice details from 'invoice.paid' payload: {:?}", err); + error!("{}", reason); + StripeWebhookError::ServerError(reason) })?; // TODO