public static WebProtocolException ToWebProtocolException(this Exception ex)
        {
            ex.AddDbgMsg("Exception converted to WebProtocolException.");
            ex.Trace();

            Reason reason = new Reason {
                Message = ex.ToUserString(), Code = ex.GetErrorCode()
            };
            ErrorEntity errorEntity = new ErrorEntity {
                Reason = reason
            };

            HttpStatusCode statusCode = ex.GetStatusCode();

            if (WebOperationContext.Current != null && WebOperationContext.Current.OutgoingResponse != null)
            {
                // -- if comes from web
                WebOperationContext.Current.OutgoingResponse.ContentType = Utils.FaultContentType;
                WebOperationContext.Current.OutgoingResponse.StatusCode  = statusCode;
            }

            WebProtocolException webProtocolException = new WebProtocolException(statusCode, ex.ToUserString(), errorEntity, ex, true);

            return(webProtocolException);
        }
Пример #2
0
        protected void Application_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();

            if (null == ex)
            {
                return;
            }

            System.Threading.ThreadAbortException threadAbortException = ex as System.Threading.ThreadAbortException;
            if (null != threadAbortException)
            {
                return;
            }

            string requestUrl = HttpContext.Current.Request.Url.ToString();

            ex.AddDbgMsg("Request = {0}", requestUrl);

            if (ex.Message == "File does not exist." && requestUrl.Contains("CmgGeneralConfig.svc"))
            {
                // Suppress errors from configuration services to avoid main log pollution
                Tracer.Trace("Suppressed exception from configuration services: " + ex.ToDebugString());
                ex.Swallow();
            }
            else
            {
                ex.Trace();
            }

            Server.ClearError();
        }