Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

wrap in try catch

Steven Tey92e40bc53319
diff --git a/apps/web/app/api/stripe/integration/webhook/customer-created.ts b/apps/web/app/api/stripe/integration/webhook/customer-created.ts
index fb2eb5d7cd..7439c9c4f0 100644
--- a/apps/web/app/api/stripe/integration/webhook/customer-created.ts
+++ b/apps/web/app/api/stripe/integration/webhook/customer-created.ts
@@ -26,16 +26,21 @@ export async function customerCreated(event: Stripe.Event) {
if (customer) {
// if customer exists (created via /track/lead)
// update it with the Stripe customer ID (for future reference by invoice.paid)
- await prisma.customer.update({
- where: {
- id: customer.id,
- },
- data: {
- stripeCustomerId: stripeCustomer.id,
- },
- });
+ try {
+ await prisma.customer.update({
+ where: {
+ id: customer.id,
+ },
+ data: {
+ stripeCustomerId: stripeCustomer.id,
+ },
+ });
- return `Dub customer with ID ${customer.id} updated with Stripe customer ID ${stripeCustomer.id}`;
+ return `Dub customer with ID ${customer.id} updated with Stripe customer ID ${stripeCustomer.id}`;
+ } catch (error) {
+ console.error(error);
+ return `Error updating Dub customer with ID ${customer.id}: ${error}`;
+ }
}
// otherwise create a new customer
diff --git a/apps/web/app/api/stripe/integration/webhook/customer-updated.ts b/apps/web/app/api/stripe/integration/webhook/customer-updated.ts
index 7c5c2512ef..9335dcc73a 100644
--- a/apps/web/app/api/stripe/integration/webhook/customer-updated.ts
+++ b/apps/web/app/api/stripe/integration/webhook/customer-updated.ts
@@ -27,19 +27,24 @@ export async function customerUpdated(event: Stripe.Event) {
});
if (customer) {
- await prisma.customer.update({
- where: {
- id: customer.id,
- },
- data: {
- externalId: dubCustomerExternalId,
- stripeCustomerId: stripeCustomer.id,
- name: stripeCustomer.name,
- email: stripeCustomer.email,
- },
- });
+ try {
+ await prisma.customer.update({
+ where: {
+ id: customer.id,
+ },
+ data: {
+ externalId: dubCustomerExternalId,
+ stripeCustomerId: stripeCustomer.id,
+ name: stripeCustomer.name,
+ email: stripeCustomer.email,
+ },
+ });
- return `Dub customer with ID ${customer.id} updated.`;
+ return `Dub customer with ID ${customer.id} updated.`;
+ } catch (error) {
+ console.error(error);
+ return `Error updating Dub customer with ID ${customer.id}: ${error}`;
+ }
}
// otherwise create a new customer