2 Replies Latest reply on Mar 26, 2013 6:49 AM by Peter Probst

    Customize Server Error Handling

    Peter Probst Newbie



      is there a way to customize the error handling on server side? We are using rpc calls and want to catch all server errors, make some computation, and then send the errors forth to the clients - but not in every rpc call, more in a generic manner. We have not found a method for doing this. Now we are deciding to use the errai code and customize the ErraiServiceImpl. But this adds an additionally maintaining burden.

      Has anyone an idea of doing this better?

      Thanks, Peter

        • 1. Re: Customize Server Error Handling
          Jonathan Fuerth Master

          Hi Peter,


          While it's true that Errai doesn't provide its own server-side RPC interceptor facility, we do support CDI interceptors for RPC calls.


          The Weld reference guide has a chapter about interceptors: http://docs.jboss.org/weld/reference/latest/en-US/html/interceptors.html


          Here's the CDI interceptor code from our test suite. You could implement something similar in your app:


          First, make an interceptor binding annotation:


          @Target({ ElementType.METHOD, ElementType.TYPE })
          public @interface InterceptedRpc {


          Then create the interceptor for that binding (note the custom @InterceptedRpc interceptor binding annotation at the class level):


          public class RpcInterceptor {
              public Object aroundInvoke(InvocationContext ctx) throws Exception {
                String parm = (String) ctx.getParameters()[0];
                parm += "_intercepted";
                ctx.setParameters(new Object[]{parm});
                return ctx.proceed();


          Finally, for each server-side service impl method you want your interceptor to operate on, apply your custom interceptor binding annotation:


          public class InterceptedRemoteImpl implements MyInterceptedRemote {
            public String interceptedCall(String callString) {
              return callString;


          Hope that helps!



          • 2. Re: Customize Server Error Handling
            Peter Probst Newbie

            Hello Jonathan,

            thank you for your valuable information. We have tested this solution and it works like a charm. Problem solved!