Exemplo n.º 1
0
        private async Task <object> ExecuteAsyncInternal(IRestRequest request, Type type)
        {
            var result = await _client.ExecuteAsync(request);

            if (result.StatusCode >= 400)
            {
                // have to read the bytes so .Content doesn't get populated
                //var content = result.RawBytes.AsString();
                //var json = JObject.Parse(content);
                //var newJson = new JObject();
                //newJson["RestException"] = json;
                //result.Content = null;
                //result.RawBytes = Encoding.UTF8.GetBytes(newJson.ToString());

                // have to read the bytes so .Content doesn't get populated
                string restException = "{{ \"RestException\" : {0} }}";
                var    content       = result.RawBytes.AsString(); //get the response content
                var    newJson       = string.Format(restException, content);

                result.Content  = null;
                result.RawBytes = Encoding.UTF8.GetBytes(newJson.ToString());
            }

            var deserializer = new RestRT.Deserializers.JsonDeserializer();

            return(deserializer.Deserialize(result, type));
        }
Exemplo n.º 2
0
		private async Task<object> ExecuteAsyncInternal(IRestRequest request, Type type)
		{
            var result = await _client.ExecuteAsync(request);

            if (result.StatusCode >= 400)
            {
                // have to read the bytes so .Content doesn't get populated
                //var content = result.RawBytes.AsString();
                //var json = JObject.Parse(content);
                //var newJson = new JObject();
                //newJson["RestException"] = json;
                //result.Content = null;
                //result.RawBytes = Encoding.UTF8.GetBytes(newJson.ToString());

                // have to read the bytes so .Content doesn't get populated
                string restException = "{{ \"RestException\" : {0} }}";
                var content = result.RawBytes.AsString(); //get the response content
                var newJson = string.Format(restException, content);

                result.Content = null;
                result.RawBytes = Encoding.UTF8.GetBytes(newJson.ToString());
            }

            var deserializer = new RestRT.Deserializers.JsonDeserializer();
            return deserializer.Deserialize(result, type);
		}