Esempio n. 1
0
        public override void OnException(HttpActionExecutedContext context)
        {
            if (context == null || !HttpContext.Current.IsCustomErrorEnabled)
            {
                base.OnException(context);

                return;
            }

            if (context.Exception != null)
            {
                _log.Error(context.Exception, "Unhandled exception");
            }
            else
            {
                _log.Warn("Unhandled exception. Target exception was not found in the ExceptionContext.");
            }

            WebErrorHandler.Handle(HttpContext.Current, context.Exception);

            context.Response = new HttpResponseMessage()
            {
                ReasonPhrase = null,
                Content      = null,
                StatusCode   = (HttpStatusCode)HttpContext.Current.Response.StatusCode
            };
        }
    static IEnumerator worker(WWW www, WebResponseHandler responseHandler, WebErrorHandler errorHandler)
    {
        yield return(www);

        if (www.error != null)
        {
//			Debug.Log ("Request to " + www.url + " failed");
            Debug.Log("WWW error: " + www.error);
            Debug.Log(www.responseHeaders);
            Debug.Log(www.url);
            Debug.Log(www.ToString());
            Debug.Log(www.text);
            // Debug.Log(www.data);
            if (errorHandler != null)
            {
                errorHandler(www.error);
            }
        }
        else
        {
//			Debug.Log ("Request to " + www.url + " succeeded");
            if (responseHandler != null)
            {
                responseHandler(www.text);
            }
        }
    }
Esempio n. 3
0
        public string ErrorHandler()
        {
            try
            {
                string x = null;
                x.ToString();
            }
            catch (Exception ex)
            {
                var eh = new WebErrorHandler(ex);
                return(eh.ToString());
            }

            return(null);
        }
Esempio n. 4
0
    static IEnumerator worker( WWW www, WebResponseHandler responseHandler, WebErrorHandler errorHandler)
    {
        yield return www;

        if( www.error != null ) {
        //			Debug.Log ("Request to " + www.url + " failed");
            Debug.Log( "WWW error: " + www.error );
            if (errorHandler != null)
                errorHandler(www.error);
        } else {
        //			Debug.Log ("Request to " + www.url + " succeeded");
            if (responseHandler != null)
                responseHandler(www.text);
        }
    }
Esempio n. 5
0
        protected void Application_Error()
        {
            var exception = Context.Server.GetLastError();

            if (exception != null)
            {
                _log.Error(exception, "Application error.");

                if (Context.IsCustomErrorEnabled)
                {
                    WebErrorHandler.Handle(Context, exception);
                }
            }

            CompleteRequest();
        }
 public static Coroutine request( string url, byte[] data, Dictionary<string, string> headers, WebResponseHandler callback, WebErrorHandler errorHandler)
 {
     return Scheduler.startCoroutine(worker( new WWW(url, data, headers), callback, errorHandler));
 }
Esempio n. 7
0
 public static Coroutine request(string url, byte[] data, Hashtable headers, WebResponseHandler callback, WebErrorHandler errorHandler)
 {
     return(Scheduler.startCoroutine(worker(new WWW(url, data, headers), callback, errorHandler)));
 }
Esempio n. 8
0
        protected void Application_Error()
        {
            try
            {
                Exception serverException = Server.GetLastError();

                WebErrorHandler errorHandler;

                // Try to log the inner Exception since that's what
                // contains the 'real' error.
                if (serverException.InnerException != null)
                {
                    serverException = serverException.InnerException;
                }

                errorHandler = new WebErrorHandler(serverException);

                // MUST clear out any previous response in case error occurred in a view
                // that already started rendering
                Response.Clear();


                // Log the error if specified
                if (LogManagerConfiguration.Current.LogErrors)
                {
                    errorHandler.Parse();

                    //try
                    //{
                    WebLogEntry entry = new WebLogEntry(serverException, this.Context);
                    entry.Details = errorHandler.ToString();

                    LogManager.Current.WriteEntry(entry);
                    //}
                    //catch {  /* Log Error shouldn't kill the error handler */ }
                }

                // Retrieve the detailed String information of the Error
                string ErrorDetail = errorHandler.ToString();

                // Optionally email it to the Admin contacts set up in WebStoreConfig
                if (!string.IsNullOrEmpty(App.Configuration.ErrorEmailAddress))
                {
                    AppWebUtils.SendAdminEmail(App.Configuration.ApplicationTitle + "Error: " + Request.RawUrl, ErrorDetail, "",
                                               App.Configuration.ErrorEmailAddress);
                }


                // Debug modes handle different error display mechanisms
                // Default  - default ASP.Net - depends on web.config settings
                // Developer  - display a generic application error message with no error info
                // User  - display a detailed error message with full error info independent of web.config setting
                if (App.Configuration.DebugMode == DebugModes.DeveloperErrorMessage)
                {
                    Server.ClearError();
                    Response.TrySkipIisCustomErrors = true;
                    ErrorController.ShowErrorPage("Application Error", "<div class='codedisplay'><pre id='Code'>" + HttpUtility.HtmlEncode(ErrorDetail) + "</pre></div>");
                    return;
                }

                else if (App.Configuration.DebugMode == DebugModes.ApplicationErrorMessage)
                {
                    string StockMessage =
                        "The Server Administrator has been notified and the error logged.<p>" +
                        "Please continue by either clicking the back button or by returning to the home page.</p>" +
                        "<p><b><a href='" + Request.ApplicationPath + "'>Click here to continue...</a></b></p>";

                    // Handle some stock errors that may require special error pages
                    HttpException httpException = serverException as HttpException;
                    if (httpException != null)
                    {
                        int HttpCode = httpException.GetHttpCode();
                        Server.ClearError();

                        if (HttpCode == 404) // Page Not Found
                        {
                            Response.StatusCode = 404;
                            ErrorController.ShowErrorPage("Page not found",
                                                          "You've accessed an invalid page on this Web server. " +
                                                          StockMessage, null);
                            return;
                        }
                        if (HttpCode == 401) // Access Denied
                        {
                            Response.StatusCode = 401;
                            ErrorController.ShowErrorPage("Access Denied",
                                                          "You've accessed a resource that requires a valid login. " +
                                                          StockMessage);
                            return;
                        }
                    }

                    // Display a generic error message
                    Server.ClearError();
                    Response.StatusCode = 500;

                    Response.TrySkipIisCustomErrors = true;

                    ErrorController.ShowErrorPage("Application Error",
                                                  "We're sorry, but an unhandled error occurred on the server. " +
                                                  StockMessage);

                    return;
                }

                return;
            }
            catch (Exception ex)
            {
                // Failure in the attempt to report failure - try to email
                if (!string.IsNullOrEmpty(App.Configuration.ErrorEmailAddress))
                {
                    AppWebUtils.SendAdminEmail(App.Configuration.ApplicationTitle + "Error: " + Request.RawUrl,
                                               "Application_Error failed!\r\n\r\n" +
                                               ex.ToString(), "", App.Configuration.ErrorEmailAddress);
                }

                // and display an error message
                Server.ClearError();
                Response.StatusCode             = 500;
                Response.TrySkipIisCustomErrors = true;

                ErrorController.ShowErrorPage("Application Error Handler Failed",
                                              "The application Error Handler failed with an exception." +
                                              (App.Configuration.DebugMode == DebugModes.DeveloperErrorMessage ? "<pre>" + ex.ToString() + "</pre>" : ""), null);
            }
        }