add more error management to ipfs

This commit is contained in:
Jonathan Rainville 2018-05-28 15:43:27 -04:00
parent 9338b6e37f
commit 7a754ac97f
1 changed files with 13 additions and 1 deletions

View File

@ -33,7 +33,17 @@ class IPFSProcess extends ProcessWrapper {
const self = this;
const child = child_process.spawn('ipfs', ['daemon']);
let lastMessage;
child.on('error', (err) => {
err = err.toString();
console.error('IPFS error: ', err);
});
child.stderr.on('data', (data) => {
data = data.toString();
console.log(`IPFS error: ${data}`);
});
child.stdout.on('data', (data) => {
data = data.toString();
if (!self.readyCalled && data.indexOf('Daemon is ready') > -1) {
self.readyCalled = true;
self.send({result: constants.storage.initiated});
@ -44,7 +54,9 @@ class IPFSProcess extends ProcessWrapper {
child.on('exit', (code) => {
if (code) {
console.error('IPFS exited with error code ' + code);
console.error(lastMessage);
if (lastMessage) {
console.error(lastMessage);
}
}
});
}