Fixed #1. If connection is lost, then function onError is called