Add onError callback

Useful if you want to execute some custom code when error happens