更新w/附加信息- 18
随着我进一步测试,该错误似乎被隔离到“this.response.end(Json)”;请参见下面的注释:
非发票事件: a)“this.response.end(obj(obj,{indent: true})”;“works &revers200b) "this.response.end(EJSON.stringify(obj));”本地服务器上没有错误,条形仪表板上有‘无法连接’的错误,并且不返回代码200。
条形发票事件: a)“this.response.end(obj(obj,{indent: true}));”抛出错误-请参阅下面的详细信息。( b)“this.response.end(EJSON.stringify(Obj))”;“本地服务器上没有错误,条形仪表板上有‘无法连接’的错误,并且不返回代码200。
任何洞察力都将不胜感激。
我与Stripe API有一些问题,并寻求一些帮助或洞察力。我正在使用ngrok在本地测试Stripe,并且一切正常工作,直到我向任何Stripe‘In发单’事件类型(例如invoice.payment_succeeded)提出请求为止。当我对任何‘发票’事件类型运行测试时,我会得到以下几个错误:
///error message start///
events.js:183
throw er; // Unhandled 'error' event
^
Error: write after end
at write_ (_http_outgoing.js:622:15)
at ServerResponse.write (_http_outgoing.js:617:10)
at IncomingMessage.ondata (_stream_readable.js:639:20)
at emitOne (events.js:116:13)
at IncomingMessage.emit (events.js:211:7)
at IncomingMessage.Readable.read (_stream_readable.js:475:10)
at flow (_stream_readable.js:846:34)
at resume_ (_stream_readable.js:828:3)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
///error message end///'Test webhook error: Unable to connect'同样,只有当我向任何Stripe 'invoice'事件类型(例如invoice.payment_succeeded)发出请求时,这才会中断。
我联系了斯特里普,看是否还有什么我应该考虑的,但是他们说他们的情况很好。
最后一点,为了让ngrok运行,我使用了'ngrok http 3000'。
也就是说,我的服务器端web钩子代码如下所示。如果有人对造成这一错误的原因有任何洞察力,任何洞察力都将受到赞赏。
///server side webhook code start///
Router.route('/webhooks/stripe', { where: 'server' })
.get(function () {
console.log('getter');
this.response.end('closing...');
})
.post(function () {
console.log('post function initiated');
// stores payload as string
var obj = this.request.body;
console.log("print obj var");
console.log(obj);
// saves as indented string to send as response
var json = EJSON.stringify(obj, {indent: true});
this.response.writeHead(200, {
'Content-Length': json.length,
'Content-Type': 'application/json'
});
this.response.end(json);
})
.put(function () {
console.log('put');
});
///server side webhook code end///发布于 2018-12-19 20:57:46
我解决了这个问题。为了参考和后代,我删除了下面的注释代码,并手动添加了我的状态代码(即this.response.statusCode = 200;)。这件事起了作用,解决了这个问题。
///code snippet start///
var json = EJSON.stringify(obj, {indent: true});
//this is the code i removed
// this.response.writeHead(200, {
// 'Content-Length': json.length,
// 'Content-Type': 'application/json'
// });
//this is the code i added to send a manual status code
this.response.statusCode = 200;
this.response.end(json);
///code snippet end///https://stackoverflow.com/questions/53826812
复制相似问题