Skip to content

Commit

Permalink
Merge pull request #1210 from elie222/fix/stripe-webhook-error-response
Browse files Browse the repository at this point in the history
  • Loading branch information
Elie Steinbock authored and GitHub committed Jan 5, 2026
2 parents b23d2e3 + 65e9815 commit 952c0a2
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions apps/web/app/api/stripe/webhook/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,22 @@ export const POST = withError("stripe/webhook", async (request) => {

if (!signature) return NextResponse.json({}, { status: 400 });

async function doEventProcessing() {
if (typeof signature !== "string") throw new Error("Header isn't a string");

if (!env.STRIPE_WEBHOOK_SECRET)
throw new Error("STRIPE_WEBHOOK_SECRET is not set");

const event = getStripe().webhooks.constructEvent(
body,
signature,
env.STRIPE_WEBHOOK_SECRET,
);

after(() => processEvent(event, logger));
if (typeof signature !== "string") {
throw new Error("Header isn't a string");
}

try {
await doEventProcessing();
} catch (error) {
logger.error("Error processing event", { error });
if (!env.STRIPE_WEBHOOK_SECRET) {
throw new Error("STRIPE_WEBHOOK_SECRET is not set");
}

const event = getStripe().webhooks.constructEvent(
body,
signature,
env.STRIPE_WEBHOOK_SECRET,
);

after(() => processEvent(event, logger));

return NextResponse.json({ received: true });
});

Expand Down

0 comments on commit 952c0a2

Please sign in to comment.