Return an error object on connection failure

Fixes #9.