How to define an error handler callback