I use Puppeteer library to open an URL and process all requests' responses. Sometimes inside the event listener page.on('response')
I need to throw an error like in the example below. But I'm unable to catch these exceptions in any way, I always got the unhandled promise rejection
error. How can I handle these exceptions? I don't want to use process.on('unhandledRejection')
because it doesn't solve my problem at all.
const puppeteer = require('puppeteer');
(async () => {
try {
const browser = await puppeteer.launch();
const page = await browser.newPage();
page.on('response', (request) => {
throw 'response error';
});
await page.goto('http://google.com/');
browser.close();
} catch (e) {}
})();