[CLOSED] DirectMethod error wrapping

  1. #1

    [CLOSED] DirectMethod error wrapping

    Hello.

    I need an opportunity to wrap each exception thrown form direct methods on server-side. I would like generate a unique key for each exception and return this info to the client. Could you suggest how it could be done, without wrapping each direct method on our application? Is there an opportunity to provide custom error handler on server side?

    Best regards.
    Last edited by Daniil; Apr 09, 2014 at 1:39 AM. Reason: [CLOSED]
  2. #2
    If an exception was thrown in a direct method then the following properties will contain false and message values
    Ext.Net.ResourceManager.AjaxSuccess
    Ext.Net.ResourceManager.AjaxErrorMessage
    You can modify message property as required at PreRender event (for example, add special prefix to AjaxErrorMessage and get that prefix in the failure handler)

    For example
    <%@ Page Language="C#" %>
    
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <script runat="server">
        [DirectMethod]
        public void ExceptionMethod()
        {
            throw new Exception("Exception message");
        }
    
    
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
    
    
            if (!ResourceManager.AjaxSuccess)
            {
                ResourceManager.AjaxErrorMessage = "[GUID]" + Guid.NewGuid() + "[/GUID]" + ResourceManager.AjaxErrorMessage;
            }
        }
    </script>
    
    
    <!DOCTYPE html>
    
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    
    
        <script type="text/javascript">
            function checkMessage(msg) {
                var match = msg && msg.match(/\[GUID\](.+?)\[\/GUID\]/);
                if (match) {
    	            alert(match[1]);
                }
            }
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server">
                <Listeners>
                    <AjaxRequestException Handler="checkMessage(result.errorMessage);" />
                </Listeners>
            </ext:ResourceManager>
    
    
            <ext:Button runat="server" Text="Click" Handler="App.direct.ExceptionMethod();" />
        </form>
    </body>
    </html>
    Vladimir Shcheglov
    Sr. Developer
  3. #3
    We're leveraging PostSharp AOP framework postsharp.net to handle cross-cutting concerns like logging or exception wrapping/shielding of various contexts in a centralized way using custom Aspects. You can look at their examples at http://doc.postsharp.net/postsharp-3...f4dcf156e3.htm and http://doc.postsharp.net/postsharp-3...929e245de3.htm. This framework is robust, easy to learn and use and fairly light compared to MS EntLib. Let me know if you'd like more details.
  4. #4
    Hello.

    How can I log the exceptions in the static direct methods?
    <script runat="server">
        [DirectMethod]
        public static void ExceptionMethod()
        {
            throw new Exception("Exception message");
        }
    </script>
  5. #5
    I am afraid there is no simple way to catch it globally. There is the same problem with page methods:
    http://stackoverflow.com/questions/7...ption-handling
  6. #6
    Maybe
    [DirectMethod(RethrowException=true)]
    public static void ExceptionStaticMethod()
    and listen to Application_Error in Global.asax.
  7. #7
    Thank you for your suggestion.
  8. #8
    So, does it work for you well?

Similar Threads

  1. Replies: 1
    Last Post: Nov 05, 2012, 8:22 PM
  2. [CLOSED] DirectMethod in customcontrol error
    By Pablo_Azevedo in forum 1.x Premium Help
    Replies: 8
    Last Post: Jun 22, 2012, 8:56 PM
  3. [CLOSED] Error when processing DirectMethod on TreePanel
    By ewgoforth in forum 1.x Premium Help
    Replies: 4
    Last Post: Nov 26, 2010, 8:41 AM
  4. [CLOSED] DirectMethod Grid Editor error
    By rthiney in forum 1.x Premium Help
    Replies: 1
    Last Post: May 21, 2010, 2:02 PM
  5. [CLOSED] wrapping in textarea
    By gokcemutlu in forum 1.x Premium Help
    Replies: 13
    Last Post: Sep 04, 2009, 4:37 AM

Tags for this Thread

Posting Permissions