Node.js处理Stripe Webhook数据时遭遇JSON解析错误及循环结构转JSON问题的求助
Node.js处理Stripe Webhook数据时遭遇JSON解析错误及循环结构转JSON问题的求助
各位大佬求助!这个问题我已经碰到好多次了,找了各种解决方案都不管用。当Stripe的Webhook数据过来时,我先是遇到了unexpected token o的错误,于是尝试用stringify再parse处理数据,结果又出现了新的错误:UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON。控制台打印出来的内容是符合预期的,但就是没法正常使用——哪怕我完全照着Stripe官方给的示例代码写也不行。
下面是我目前的代码,有没有大佬知道怎么解决这个问题?
app.post('/webhook', express.raw({type: 'application/json'}), async (request, response) => { console.log(request.body); let event; try { event = await stripe.webhooks.constructEvent( request.body, request.headers['stripe-signature'], endpointSecret ); const customerSubscriptionUpdated = event.data.object; } catch (err) { response.status(400).send(`Stupid Webhook Error: ${err.message}`); return; } // Return a 200 response to acknowledge receipt of the event response.send(); });
备注:内容来源于stack exchange,提问作者CoreyRS
相关产品推荐
相关产品推荐

