Closed teckays closed 5 years ago
Please provide more details.
Facing issue while handling stream errors, when performing stream.write(...) neither stream.on('error', ...) is working nor is try catch, not able to handle errors. Application crashing
const clickhouseStream = await clickhouse.query(
INSERT INTO ${datasetName} FORMAT JSONEachRow
,
async error => {
console.log('error', error);
res.status(500).send(error);
}
);
await clickhouseStream.write(JSON.stringify(f)); <= crash here
await clickhouseStream.end();
clickhouseStream.on('error', async error => { . <= does not execute this block console.log('error', error); res.status(500).send(error); });
events.js:137 throw er; // Unhandled 'error' event ^
Error: connect ECONNREFUSED 127.0.0.1:8123
How to resolve this issue?
@ranjanr46 Better understanding of possible error contexts in JS should help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch
Closing, because there is no activity.
I am trying to gracefully handle stream errors but neither
stream.on('error', ...)
nor wrapping the stream in atry catch
actually work. Any particular ways to gracefully handle the errors without having the app to crash?