Passing errors back in a ext direct call

已查看 80 次
跳至第一个未读帖子

Steve Schreiner

未读,
2014年6月28日 13:38:032014/6/28
收件人 extdire...@googlegroups.com
Suppose I have a simple ext direct method ( @ExtDirectMethod ) and it returns a simple class object to the client.  How would I pass back any errors encountered within this method back to the client in my response?  Thanks

ralph

未读,
2014年6月28日 14:03:332014/6/28
收件人 extdire...@googlegroups.com
Hi

You could catch the errors/exceptions in your code and put the error message in an additional field of the result object.
Or you let extdirectspring handle the exceptions. 
When an @ExtDirectMethod method throws an exception extdirectspring catches and wraps it into a response that looks like this:

[{"type":"exception","message":"Server Error","tid":2,"action":"myServerMethod","method":"doSomething"}]

The client receives this informations as the second parameter of the callback.

myServerMethod.doSomething(param1, param2, function(result, e) {
   if (e.status) {
      //everything ok
   } else {
      //something wrong
   }
});


e is of type RemotingEvent and contains these properties:

  • status - true if the call was successful, false if something went wrong.
  • result - contains the same data as the first parameter
  • type - is 'rpc' or 'exception' when an error occurred
  • action - the name of the bean. In this example 'myServerMethod'
  • method - the name of the method ('doSomething')
  • tid - a transaction number
  • getTransaction() - retrieves the transaction used in this server call. This object contains some more information about the call. e.g. transaction.args contains the arguments the method was originally called with.

Steve Schreiner

未读,
2014年6月28日 14:26:042014/6/28
收件人 extdire...@googlegroups.com
Thanks for the reply Ralph. Is there any way to have the exception message passed back (or customized) when extdirectspring handles the exception?  Currently the message that is returned is simply "Server Error".  I would like it to include details of the actual exception.

Steve


-- The contents of this message, together with any attachments, are intended only for the use of the individual or entity to which they are addressed and may contain confidential information. If you are not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this message, or any attachment, is strictly prohibited. If you have received this message in error, please contact the sender immediately and permanently delete or destroy the material/information.


--
You received this message because you are subscribed to a topic in the Google Groups "extdirectspring" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/extdirectspring/Ax5B8m6lvWU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to extdirectspri...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ralph

未读,
2014年6月28日 14:43:132014/6/28
收件人 extdire...@googlegroups.com
You can customize this with a Configuration object. 

The configuration allows you to map an exception to a specific message.
Here an example with Spring Java Config. This sends the message "accessdenied" instead of "Server Error" when 
a AccessDeniedException occurs.

You can also specify if the result contains the complete stacktrace (not recommended for production) with the setSendStacktrace(..) method

@Bean
public ch.ralscha.extdirectspring.controller.Configuration configuration() {
  ch.ralscha.extdirectspring.controller.Configuration config = new ch.ralscha.extdirectspring.controller.Configuration();
  config.setSendStacktrace(true);
  config.setExceptionToMessage(Collections.singletonMap(AccessDeniedException.class, "accessdenied"));

  return config;
}
 

回复全部
回复作者
转发
0 个新帖子