Handle connection errors.
Merge pull request #125 from astaric/handle-connection-errors

Handle connection errors.