SetResponse() private méthode

private SetResponse ( IDisposable response ) : void
response IDisposable
Résultat void
Exemple #1
0
        public static SignalRError GetError(this Exception ex)
        {
            ex = ex.Unwrap();
            var wex = ex as WebException;

            var error = new SignalRError(ex);

            if (wex != null && wex.Response != null)
            {
                var response = wex.Response as HttpWebResponse;
                if (response != null)
                {
                    error.SetResponse(response);
                    error.StatusCode = response.StatusCode;
                    Stream originStream = response.GetResponseStream();

                    if (originStream.CanRead)
                    {
                        // We need to copy the stream over and not consume it all on "ReadToEnd".  If we consumed the entire stream GetError
                        // would only be able to be called once per Exception, otherwise you get inconsistent ResponseBody results.
                        Stream stream = Clone(originStream);

                        // Consume our copied stream
                        using (var sr = new StreamReader(stream))
                        {
                            error.ResponseBody = sr.ReadToEnd();
                        }
                    }
                }
            }

            return error;
        }
        public static SignalRError GetError(this Exception ex)
        {
            ex = ex.Unwrap();
            var wex = ex as WebException;

            var error = new SignalRError(ex);

            if (wex != null && wex.Response != null)
            {
                var response = wex.Response as HttpWebResponse;
                if (response != null)
                {
                    error.SetResponse(response);
                    error.StatusCode = response.StatusCode;
                    Stream originStream = response.GetResponseStream();

                    if (originStream.CanRead)
                    {
                        // We need to copy the stream over and not consume it all on "ReadToEnd".  If we consumed the entire stream GetError
                        // would only be able to be called once per Exception, otherwise you get inconsistent ResponseBody results.
                        Stream stream = Clone(originStream);

                        // Consume our copied stream
                        using (var sr = new StreamReader(stream))
                        {
                            error.ResponseBody = sr.ReadToEnd();
                        }
                    }
                }
            }

            return(error);
        }
Exemple #3
0
        private static SignalRError GetHttpClientException(Exception ex)
        {
            var error = new SignalRError(ex);
            var hex   = ex as HttpClientException;

            if (hex != null && hex.Response != null)
            {
                var response = hex.Response as HttpResponseMessage;

                if (response != null)
                {
                    error.SetResponse(response);
                    error.StatusCode   = response.StatusCode;
                    error.ResponseBody = response.Content.ReadAsStringAsync().Result;
                }
            }

            return(error);
        }
        private static SignalRError GetHttpClientException(Exception ex)
        {
            var error = new SignalRError(ex);
            var hex = ex as HttpClientException;

            if (hex != null && hex.Response != null)
            {
                var response = hex.Response as HttpResponseMessage;

                if (response != null)
                {
                    error.SetResponse(response);
                    error.StatusCode = response.StatusCode;
                    error.ResponseBody = response.Content.ReadAsStringAsync().Result;
                }
            }

            return error;
        }