I am not sure what you requirement is, but read this page: https://docs.chef.io/handlers.html
If want to run custom scripts as part of an event handler then yes you can do that like this:
on :run_failed do |exception|
<ruby code here>
This will do something when chef run fails. You can put this inside a recipe and hook it on top of your run list.