Improve the request handling code and propagate an error on invalid response
status code.
Improve heartbeater error handling.