Пример #1
0
        public IRaygunMessageBuilder SetExceptionDetails(Exception exception)
        {
            if (exception != null)
            {
                _raygunMessage.Details.Error = RaygunErrorMessageBuilder.Build(exception);
            }

            HttpException error = exception as HttpException;

            if (error != null)
            {
                int    code        = error.GetHttpCode();
                string description = null;
                if (Enum.IsDefined(typeof(HttpStatusCode), code))
                {
                    description = ((HttpStatusCode)code).ToString();
                }
                _raygunMessage.Details.Response = new RaygunResponseMessage()
                {
                    StatusCode = code, StatusDescription = description
                };
            }

            try
            {
                WebException webError = exception as WebException;
                if (webError != null)
                {
                    if (webError.Status == WebExceptionStatus.ProtocolError && webError.Response is HttpWebResponse)
                    {
                        HttpWebResponse response = (HttpWebResponse)webError.Response;
                        _raygunMessage.Details.Response = new RaygunResponseMessage()
                        {
                            StatusCode = (int)response.StatusCode, StatusDescription = response.StatusDescription
                        };
                    }
                    else if (webError.Status == WebExceptionStatus.ProtocolError && webError.Response is FtpWebResponse)
                    {
                        FtpWebResponse response = (FtpWebResponse)webError.Response;
                        _raygunMessage.Details.Response = new RaygunResponseMessage()
                        {
                            StatusCode = (int)response.StatusCode, StatusDescription = response.StatusDescription
                        };
                    }
                    else
                    {
                        _raygunMessage.Details.Response = new RaygunResponseMessage()
                        {
                            StatusDescription = webError.Status.ToString()
                        };
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Error retrieving response info {0}", ex.Message);
            }

            return(this);
        }
Пример #2
0
 public IRaygunMessageBuilder SetExceptionDetails(Exception exception)
 {
     if (exception != null)
     {
         _raygunMessage.Details.Error = RaygunErrorMessageBuilder.Build(exception);
     }
     return(this);
 }