File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -347,14 +347,30 @@ export async function handleSubscriptionDeleted(params: {
347347 const user = await getUserByStripeCustomerId ( customerId )
348348 const userId = user ?. id ?? null
349349
350- await db
350+ const result = await db
351351 . update ( schema . subscription )
352352 . set ( {
353353 status : 'canceled' ,
354354 scheduled_tier : null ,
355355 canceled_at : new Date ( ) ,
356356 } )
357357 . where ( eq ( schema . subscription . stripe_subscription_id , subscriptionId ) )
358+ . returning ( { id : schema . subscription . stripe_subscription_id } )
359+
360+ if ( result . length === 0 ) {
361+ logger . warn (
362+ { subscriptionId, customerId } ,
363+ 'No subscription found to cancel — may not exist in our database' ,
364+ )
365+ // Still track the event for observability
366+ trackEvent ( {
367+ event : AnalyticsEvent . SUBSCRIPTION_CANCELED ,
368+ userId : userId ?? 'system' ,
369+ properties : { subscriptionId, notFoundInDb : true } ,
370+ logger,
371+ } )
372+ return
373+ }
358374
359375 if ( userId ) {
360376 await expireActiveBlockGrants ( { userId, subscriptionId, logger } )
You can’t perform that action at this time.
0 commit comments