示例#1
0
        /*\ ****** ****** ****** ****** ****** Constructors ****** ****** ****** ****** ****** \*/
        /// <summary>
        /// Initializes a new instance of the <see cref="AirbrakeResponse"/> class.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <param name="content">The content.</param>
        public AirbrakeResponse(WebResponse response, string content)
        {
            Content = content;
            Errors  = new List<AirbrakeResponseError>();

            if (response != null)
            {
                // TryGet is needed because the default behavior of WebResponse is to throw NotImplementedException
                // when a method isn't overridden by a deriving class, instead of declaring the method as abstract.
                ContentType             = response.TryGet(x => x.ContentType);
                Headers                 = response.TryGet(x => x.Headers);
                IsFromCache             = response.TryGet(x => x.IsFromCache);
                IsMutuallyAuthenticated = response.TryGet(x => x.IsMutuallyAuthenticated);
                ResponseUri             = response.TryGet(x => x.ResponseUri);
            }

            try
            {
                Deserialize(content);
            }
            catch (Exception exception)
            {
                LogManager.GetLogger(GetType())
                          .Fatal(f => f("An error occurred while deserializing the following content:\n{0}", content), exception);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AirbrakeResponse"/> class.
        /// </summary>
        /// <param name="response">The response.</param>
        /// <param name="content">The content.</param>
        public AirbrakeResponse(WebResponse response, string content)
        {
            this.content = content;
            this.errors = new AirbrakeResponseError[0];

            if (response != null)
            {
                // TryGet is needed because the default behavior of WebResponse is to throw NotImplementedException
                // when a method isn't overridden by a deriving class, instead of declaring the method as abstract.
                this.contentLength = response.TryGet(x => x.ContentLength);
                this.contentType = response.TryGet(x => x.ContentType);
                this.headers = response.TryGet(x => x.Headers);
                this.isFromCache = response.TryGet(x => x.IsFromCache);
                this.isMutuallyAuthenticated = response.TryGet(x => x.IsMutuallyAuthenticated);
                this.responseUri = response.TryGet(x => x.ResponseUri);
            }

            try
            {
                Deserialize(content);
            }
            catch (Exception exception)
            {
                "An error occurred while deserializing the following content:\r\n{0}\r\n{1}".TraceError(content, exception);
            }

        }
        public ExceptionizerResponse(WebResponse response, string content)
        {
            this.content = content;

            if (response != null)
            {
                this.contentLength = response.TryGet(x => x.ContentLength);
                this.contentType = response.TryGet(x => x.ContentType);
                this.headers = response.TryGet(x => x.Headers);
                this.isFromCache = response.TryGet(x => x.IsFromCache);
                this.isMutuallyAuthenticated = response.TryGet(x => x.IsMutuallyAuthenticated);
                this.responseUri = response.TryGet(x => x.ResponseUri);
            }

            try
            {
                Deserialize(content);
            }
            catch (Exception)
            {
                // TODO: log
            }
        }