Refactor JobStateHandler for error handling and email notification.