Squashed commit of the following:
fixing an issue with http requests where close could cause a cyclic cycle through the end event when the method has already returned.

Fixing a bug where the response is a 4xx or 5xx and the response text is a string HTML response instead of the expected object. Throws the non-2xx error check before trying to process the object. Previously this would throw an exception. Also considering throwing in JSON validation to ensure the data is properly formatted JSON but that is a heavy regex which runs slow.