How about a simple shell:
async function leniently(promise) {
try {
return await promise
} catch(err) {
return null
}
}
Used for any promise:
const result = await leniently(stat(file, fs.constants.R_OK))
Or Promise.all(...):
const result = await leniently(Promise.all(...))
source
share