[CLOSED] [1.0] Global error handling of DirectMethods

  1. #1

    [CLOSED] [1.0] Global error handling of DirectMethods

    I am able to implement global error handling for DirectEvents since they run through normal asp.net page life cycle. However, I am not able to globally handle shared/static DirectMethods. When an error occurs, the Global.asax's Application_Error event does not fire. Looking in DirectRequestModule.cs, I notice that any DirectMethods exception is handled by Ext.net. Is it possible to expose a way for me to hook into that? It was suggested that I catch the error on the clientside, but that is not ideal. I need to log the error to the database because we track and log every exception thrown in the application. Firing off another DirectMethod to just log the error seems a little goofy to me. What if that DirectMethod fails too? Then it will go into an infinite loop.

    DirectRequestModule.cs
           private void ProcessRequest(HttpApplication app, HttpRequest request)
            {
                DirectResponse responseObject = new DirectResponse(true);
    
                try
                {
                   // ... do stuff
                }
                catch (Exception e)
                { 
                    // I want a hook into here!!!!  So I can log the exception to the database for history/tracking purposes.  This must occur on serverside and not clientside.
                    responseObject.Success = false;
                    responseObject.ErrorMessage = IsDebugging ? e.ToString() : e.Message;
                }
    
                // ... process request
                app.CompleteRequest();
            }
    Last edited by Daniil; Jul 26, 2010 at 9:24 AM.
  2. #2
    Hi,

    What if to set RethrowAjaxExceptions="true" for the ResourceManager? Does it solve your issue?
  3. #3
    What does that property do? I searched for RethrowAjaxExceptions in the forum but got no response. Here's a test page I am using plus the global.asax. When you click DirectEvent, you will see that the error is handled in global.asax page. When you click DirectMethod, I can catch it with a javascript function but I would like to handle that globally on the serverside instead so I can log it to database.

    ErrorHandling.aspx
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
    
        [DirectMethod()]
        public static void GoDirectMethod() {
            throw new Exception("GoDirectMethod");
        }
    
        public void GoDirectEvent(object sender, DirectEventArgs args) {
            throw new Exception("GoDirectEvent");
        }
        
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
    
        <script type="text/javascript">
            function onError(response, result, el, eventType, action, extraParams, o) {
                if (eventType === 'event') {
                    //ajax event already has its own error handler
                    return;
                }
    
                Ext.Msg.alert('Error', result.errorMessage);
    
                // return false will stop event from bubbling
                return false;
            }
        </script>
    
        <form id="form1" runat="server">
        <ext:ResourceManager runat="server" RethrowAjaxExceptions="true">
            <Listeners>
                <AjaxRequestException Fn="onError" />
            </Listeners>
        </ext:ResourceManager>
        <div style="padding: 10px">
            <ext:Button runat="server" Text="DirectMethod">
                <Listeners>
                    <Click Handler="Ext.net.DirectMethods.GoDirectMethod();" />
                </Listeners>
            </ext:Button>
            <ext:Button runat="server" Text="DirectEvent">
                <DirectEvents>
                    <Click OnEvent="GoDirectEvent">
                    </Click>
                </DirectEvents>
            </ext:Button>
        </div>
        </form>
    </body>
    </html>
    Global.asax
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.SessionState;
    
    namespace MyExtNetSandbox {
        public class Global : System.Web.HttpApplication {
         
            protected void Application_Error(object sender, EventArgs e) {
                //log error to database
    
                //clear error
                HttpContext.Current.Server.ClearError();
    
                //send custom response
                var r = HttpContext.Current.Response;
                r.ClearContent();
                r.StatusCode = 500;           
                r.Write("Handled in Global.asax.  Print out friendly message.");
                r.Flush();
                r.End();
    
            }
         
        }
    }
  4. #4
    Hi,

    Yes, for static methods that property doesn't work because page instance is not created and we cannot read that property.
    I have to think how we can define rethrowing exception for static direct method (may be through DirectMethod attribute)
  5. #5
    Hi,

    We have implemented that functionality. Now toy can add
    RethrowException = true
    to the DirectMethod attribute and exception will be rethrowing

    [DirectMethod(RethrowException = true)]
  6. #6
    Is there a way to globally set this instead of per DirectMethod? Thanks!
  7. #7
    nevermind, i am fine with handling static directmethods on a case by case basis. Thanks!

Similar Threads

  1. [CLOSED] Javascript Global Error Handling
    By adelaney in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 20, 2012, 8:30 PM
  2. Global Error Handling
    By wdk in forum 1.x Help
    Replies: 2
    Last Post: Apr 03, 2012, 2:34 AM
  3. [CLOSED] Global Exception Handling How to?
    By ISI in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 11, 2011, 11:57 AM
  4. [CLOSED] Global exception handling - wrong response or no failure
    By pschojer in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 13, 2010, 2:03 PM
  5. Replies: 4
    Last Post: Sep 17, 2009, 7:45 AM

Posting Permissions