You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 15:49:29