Listen to response events (on behalf of @oleurud)

This commit is contained in:
Rafa de la Torre 2018-05-31 17:06:17 +02:00
parent 0eab03a7e7
commit 332f7096d3

View File

@ -14,6 +14,21 @@ module.exports = {
return cb(err);
}
let responseEnded = false;
res
.on('error', err => {
pgstream.unpipe(res);
return cb(err);
})
.on('close', () => {
if (!responseEnded) {
return cb(new Error('Connection closed by client'));
}
})
.on('end', () => responseEnded = true);
const copyToStream = copyTo(sql);
const pgstream = client.query(copyToStream);
pgstream