Add onError callback

Useful if you want to execute some custom code when error happens
Merge pull request #2 from astashov/add-on-error-callback

Add onError callback