Check the Content-Type header that is returned from the RPC server. Only if it is application/json the data is supposed to be parsed as JSON.
This gives better reporting if the HTTP server happens to return an error that is not JSON-formatted, which is the case if it happens at a lower level before JSON-RPC kicks in.
Before: Unexpected exception caught during testing: No JSON object could be decoded
After: JSONRPC error: non-JSON HTTP response with '403 Forbidden' from server
@sipa