on_error function

Add a function to be run on error