Close the current connection when an error occurred. Fixes #17.

This is my idea about issue #17.