download
download copied to clipboard
cannot catch all error in promise chain
my test code, just simple visit a host which not exist.
const download = require('download');
download('https://www.ahostnotexisttddddd.com.hk', {
timeout: 100
}).then(result => {
console.log(result);
}).catch(() => {
console.error('error catched!')
});
out put is
error catched!
events.js:183
throw er; // Unhandled 'error' event
^
RequestError: Request timed out
at Timeout.setTimeout [as _onTimeout] (/user/test/test/node_modules/got/index.js:205:24)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
It seems that p-event just only resolved first error throwed out by got stream
.
I'm having the same problem. Even wrapped in try/catch this is terminating the program as an unhandled error.
Same here!
You can do this ugly workarround
Promise.resolve()
.then( () => {
return (async () => {
try {
return await download('https://www.ahostnotexisttddddd.com.hk', {
timeout: 100
})
} catch (err) {
throw err
}
})()
)
.then(result => {
console.log(result)
}).catch((err) => {
console.error('error catched!')
console.log(err)
})
eddited for better manage inside of a promisechain
It is very ugly but does the job. I think that the GOT package errors are not handled properly
same question here