Improved error handling

If an error response occurs, throw an appropriate error message.

The json returned in an error looks like

{
   "error": error_code
   "error_description": error_description
}

When testing the behaviour, a JSON parse error was thrown because the first couple of bytes in the response were returned seperately from the rest of the message. The JSON parsed successfully if the bytes in the stream were concatenated together.