unhandled error when a file does not exists
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!
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 This code will work :)
try {
await Promise.all(persedFiles.map(file => fs.promises.access(file.path)));
} catch (error) {
return res.status(404).send();
}