This repository was archived by the owner on Jun 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
This repository was archived by the owner on Jun 28, 2021. It is now read-only.
EventParser error at using event bus #106
Copy link
Copy link
Open
Description
I see this error at trying to use an event bus
merchant facade
SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at /Users/zestu/Finance/BitPayService/node_modules/bitpay-rest/lib/event-parser.js:35:26
at Array.forEach (<anonymous>)
at /Users/zestu/Finance/BitPayService/node_modules/bitpay-rest/lib/event-parser.js:27:11
at Array.forEach (<anonymous>)
at EventParser._transform (/Users/zestu/Finance/BitPayService/node_modules/bitpay-rest/lib/event-parser.js:22:12)
at EventParser.Transform._read (_stream_transform.js:190:10)
at EventParser.Transform._write (_stream_transform.js:178:12)
at doWrite (_stream_writable.js:415:12)
at writeOrBuffer (_stream_writable.js:399:5)
Here's the code I use:
app.get("/create_bitpay_invoice", (req, res, next) => {
client.as('merchant').post('invoices', data, function(err, invoice) {
if (err) {
// more error handling
return console.log(err);
} else {
// success
// get event bus token
client.as('merchant').get(invoice.path + 'events', function(err, buspass) {
if (err) console.log(err);
let data = {
token: buspass.token,
action:'subscribe',
events: ['payment']
};
// pipe event stream request through bitpay.EventParser
var events = client.as('merchant').get('events', data);
var parser = new bitpay.EventParser();
events.pipe(parser).on('payment', function(invoice) {
console.log('invoice is ' + invoice.status);
});
res.json({msg: invoice});
});
}
});
});
Metadata
Metadata
Assignees
Labels
No labels