call onError when necessary