Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Handling exceptions in DMI

    Hi Isomorphic,

    Could you please help me with following question.

    I run isc.DMI.call({...}). And I need to handle on client side some exceptions that were caused on server side.

    Please let me know how can I do this. Please, write some examples.

    Thanks in advance.

    #2
    The callback provided to DMI.call() receives the rpcResponse. If your method simply throws an exception, you've find that rpcResponse.status is negative and "data" contains the exception.

    For finer-grained control, return an RPCResponse from your server method, so you can call setStatus() and setData() to populate the RPCResponse however you like.

    Comment


      #3
      Thanks

      Hi Isomorphic,

      Thanks for the comment.

      P.S.
      I have found that for calling the callback() method on client side after throwing exception on server side we need define following property:

      isc.DMI.call({
      ... ,
      requestParams: {willHandleError: true}
      });

      Comment


        #4
        Yup, if you do not advertise that you want to handle an error, it will go through centralized error handling in RPCManager.handleError()

        Comment


          #5
          As usual, I don't quite get it.
          Here is my DMI.call() code:

          Code:
          DMI.call(myApp, 
                     myServerClass, 
                     myServerMethod, 
                     myRPCCallback,
                     new Object[] { param });
          1) Where exactly do I insert "requestParams: {willHandleError: true}" ? Nothing I've tried works.

          2) If I didn't add {willHandleError: true}, would the Exception I throw in the server method crash the app or could I still handle it in the RPCCallback?

          Thanks!!

          Comment


            #6
            There's currently no equivalent in the SmartGWT API to the ability to set willHandleError in SmartClient.

            If you throw an exception in your DMI, it will go to central error handling, which you can customize via adding your own ErrorHandler to RPCManager.

            Another approach would be to catch the exception and not report it as an error as far as SmartGWT is concerned (leave status as 0). Then your callback will be called normally.

            Finally, consider DataSource operations of type:"custom", they are often more convenient than RPC DMI.

            Comment


              #7
              Aha - thank you so much, you've clarified several points for me. It's the second approach that I had in mind, but I was throwing the exception in the server-side class and couldn't figure out the flow from there. I'm using DMI because this is not related to any datasource, so the custom operation doesn't seem to apply as well. I think I'll reconsider using a custom exception here (suggested to me in a code review) and just set the data with an error flag as I had originally designed.

              Thanks again!
              Last edited by susanpemble; 16 Jan 2012, 06:38.

              Comment


                #8
                Receiviing Response in Javascript method from DMI

                Hi
                I want to call Javascript callback function from Server method DSResponse Update (.......).
                Is it possible to call

                Comment

                Working...
                X