thrackle / express-zip

stream multiple files to the browser as a single zip, in pure node
MIT License
72 stars 18 forks source link

unhandled error when a file does not exists #1

Open jguillod opened 11 years ago

jguillod commented 11 years ago

I got the following error with Node aborting when trying to response.zip() an unexisting file path:

events.js:71
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: ENOENT, open '/Some/Path/to/null/file'

This exits Node even if we call the response.zip() function inside a try... catch... statment.

Could you deal with it by calling the error callback or some other way in order not to abort the Node server?

Of course I will test the file existance with fs.existsSync()

Thanks a lot for this easy to use module!

thrackle commented 11 years ago

Hi @jguillod, thanks for the feedback. What you suggest definitely sounds like it will be an improvement. I started implementing this change, but I haven't had time to publish it yet. Hopefully I'll get it out soon.

Thanks again, thrackle

Akxe commented 3 years ago

@thrackle This code will work :)

try {
  await Promise.all(persedFiles.map(file => fs.promises.access(file.path)));
} catch (error) {
  return res.status(404).send();
}