'PM2 does not restart Node JS application when this error occurs

For some reason, every time I get this particular error

/home/pi/.pm2/logs/app-error.log last 15 lines:
0|scripts | { TimeoutError: Navigation timeout of 30000 ms exceeded
0|scripts |     at Promise.then (/home/pi/node_modules/puppeteer/lib/cjs/puppeteer/common/LifecycleWatcher.js:106:111) name: 'TimeoutError' }

pm2 does not restart the node JS script.



Solution 1:[1]

It because that error doesnt crash the main thread of the application, it just prints the error from the puppeteer thread

Solution 2:[2]

Use try...catch statement to catch the error (you can log it or just do nothing) so that the script will not just hang there with the error. pm2 will be able to restart it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paja Aleksic
Solution 2 Tacaza