@@ -5,9 +5,9 @@ import { resolver, validator } from "hono-openapi/zod";
55import { z } from "zod" ;
66
77import { syncBillingBridge } from "../billing" ;
8+ import { env } from "../env" ;
89import type { AppBindings } from "../hono-bindings" ;
910import { stripeSync } from "../integration/stripe-sync" ;
10- import { Metrics } from "../metrics" ;
1111import { API_TAGS } from "./constants" ;
1212
1313const WebhookSuccessSchema = z . object ( {
@@ -69,12 +69,31 @@ webhook.post(
6969
7070 try {
7171 await stripeSync . processWebhook ( rawBody , signature ) ;
72+ } catch ( error ) {
73+ if ( env . NODE_ENV !== "production" ) {
74+ console . error ( error ) ;
75+ } else {
76+ if (
77+ error instanceof Error &&
78+ error . message === "Unhandled webhook event"
79+ ) {
80+ // stripe-sync-engine doesn't support this event type, skip silently
81+ } else {
82+ Sentry . captureException ( error , {
83+ tags : { webhook : "stripe" , event_type : stripeEvent . type } ,
84+ } ) ;
85+ return c . json ( { error : "stripe_sync_failed" } , 500 ) ;
86+ }
87+ }
88+ }
89+
90+ try {
7291 await syncBillingBridge ( stripeEvent ) ;
7392 } catch ( error ) {
7493 Sentry . captureException ( error , {
7594 tags : { webhook : "stripe" , event_type : stripeEvent . type } ,
7695 } ) ;
77- return c . json ( { error : "stripe_billing_sync_failed " } , 500 ) ;
96+ return c . json ( { error : "billing_bridge_sync_failed " } , 500 ) ;
7897 }
7998
8099 return c . json ( { ok : true } , 200 ) ;
0 commit comments