kelektiv / node-cron

Cron for NodeJS.
MIT License
8.3k stars 617 forks source link

feat: error handling on ticks #861

Open JosephVoid opened 4 months ago

JosephVoid commented 4 months ago

Description

I've added an error handling method in the CronJob class and added it to the constructors parameters. This error handling method will be called if any exception is thrown from the onTick method. Also added two new tests to confirm that it works.

Related Issue

Closes #426.

Motivation and Context

If any kind of exception occurs from the onTick method the whole process stops currently. To solve this, this feature will allow users to pass their own error handler when exceptions occur.

How Has This Been Tested?

Added two new test cases called should catch errors if errorhandler is provided & should throw errors if errorhandler is NOT provided

Screenshots (if appropriate):

Types of changes

Checklist:

JosephVoid commented 3 months ago

Hey @sheerlox,

Thanks for the review. I've incorporated all the suggestions.