Answer the question
In order to leave comments, you need to log in
Why is the error not caught in .on('error',..)?
There is this code:
function (file, res) {
fs.createReadStream(file)
.pipe(res)
.on('error', err => {
console.log(err);
...
})
.on('end', res.end);
};
Answer the question
In order to leave comments, you need to log in
.pipe() will return the stream where it will be written. Accordingly, you do not catch the error.
should be rewritten like this
fs.createReadStream(file)
.on('error', err => {
console.log(err);
...
})
.on('end', res.end)
.pipe(res)
When I get confused, I start to simplify:
var stream = fs.createReadStream(file);
stream.on('open', function () { /* ... */ });
stream.on('error', function(err) { console.log(err); });
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question