Added an error handling for connection refused to API server.

Change-Id: I4eb640e3072f880491438985872daae425e3296d