add `onError` option (close #23)