Stripe 400 Bad request catch block
bearbricknik opened this issue · comments
Hi, I discovered a problem with stripe webhooks generating a 400 Bad request. When setting up stripe webhooks and sending a product.created or any other event from relevantEvents
it directly hits the catch block without logging an error. I am unable to see the error happening as its printing an empty object {}.
if (relevantEvents.has(event.type)) {
try {
switch (event.type) {
case 'product.created':
case 'product.updated':
await upsertProductRecord(event.data.object as Stripe.Product);
break;
case 'price.created':
case 'price.updated':
await upsertPriceRecord(event.data.object as Stripe.Price);
break;
case 'customer.subscription.created':
case 'customer.subscription.updated':
case 'customer.subscription.deleted':
const subscription = event.data.object as Stripe.Subscription;
await manageSubscriptionStatusChange(
subscription.id,
subscription.customer as string,
event.type === 'customer.subscription.created'
);
break;
case 'checkout.session.completed':
const checkoutSession = event.data.object as Stripe.Checkout.Session;
if (checkoutSession.mode === 'subscription') {
const subscriptionId = checkoutSession.subscription;
await manageSubscriptionStatusChange(
subscriptionId as string,
checkoutSession.customer as string,
true
);
}
break;
default:
throw new Error('Unhandled relevant event!');
}
} catch (error) {
console.log("error: ", error)
return new Response(
JSON.stringify({ received: false, error: error }),
{
status: 400
}
);
}
}
Console => error: {}
Stripe => {
"received": false,
"error": {
}
}
Not sure what I am doing wrong here but no matter what event I am sending, its directly hitting the catch block.
Edit: I didnt use the deploy button. With deploying it directly via the deploy button its working, however setting up everything manual / running it on localhost with stripe local listeners gives me an error.
My fault. Wrong supabase setup.