express-zip icon indicating copy to clipboard operation
express-zip copied to clipboard

unhandled error when a file does not exists

Open jguillod opened this issue 13 years ago • 2 comments

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!

jguillod avatar Dec 20 '12 19:12 jguillod

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

thrackle avatar Jan 27 '13 17:01 thrackle

@thrackle This code will work :)

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

Akxe avatar Feb 13 '21 01:02 Akxe