Handle errors better

Use `err` returned from `nscale-sdk`.
React to `error` and `end` events on the SDK object.
Don't try disconnecting from the server if we're not connected.