Fix transport connection not being closed on error.

### To reproduce the problem:

Use the example code from the README.md file to try to authenticate. If your username/password/tenant ID are correct, everything works as expected.

If the auth details are wrong, the app doesn’t terminate for a long time.

### Cause:

The 'data' events were being ignored if there was an error. That left an outstanding HTTP connection that didn’t get released until the socket timed out.

### Fix:

Re-factored the transport code to always handle the 'data' and 'end' events. Check for bad HTTP statusCode in the 'end' event and proceed accordingly.