title: JAX-RS jersey handle WebApplicationException
body: <p>JAX-RS jersey handle WebApplicationException </p>
  
  <p>Hi,</p>
  
  <p>I'm trying to handle WebApplicationException using MyWebApplicationExceptionMapper, but it is not working.</p>
  
  <pre><code>@Path("/v1")
  public class MyHandler {
  
      @POST
      @Path("/test")
      @Consumes({ MediaType.APPLICATION_JSON})
      @Produces({ MediaType.APPLICATION_JSON})
      public Response getTouchpointPost(@QueryParam("key") KeyParam KeyParam){
      ..
      }
  }
   public class KeyParam extends AbstractParam&lt;String&gt; {
  
      public KeyParam(String param) {
          super(param);
      }
  
      @Override
      protected String parse(String param) {
          return checkKey(param);
      }
  
      private String checkKey(String key) {
      // throws IllegalArgumentException if {key expression} is false
          com.google.common.base.Preconditions.checkArgument(isValid(key), "Invalid key %s", key);
          return key;
      }
  }
  </code></pre>
  
  <p>when <code>checkKey()</code> throws IllegalArgumentException, it is caught in catch block  and re-thrown as WebApplicationException.</p>
  
  <pre><code>    public abstract class AbstractParam&lt;V&gt; {
          // some code
      public AbstractParam(@JsonProperty("param") String param) {
      // some code
  
      } catch (Exception e) {
          LOGGER.warn("Exception decoding parameter", e);
          throw new WebApplicationException(onError(param, e));
      }
  }
  
  
  @Provider
  public class MyWebApplicationExceptionMapper extends
          BaseExceptionMapper&lt;WebApplicationException&gt; {
  
      @Override
      public int getStatus(WebApplicationException e) {
          return e.getResponse().getStatus();
      }
  }
  </code></pre>
  
  <p>I have a mapper class which is trying to catch the WebApplicationException. But this mapper class is not able to catch the WebApplicationException exception.</p>
  
  <p>Can someone help me on this? This BaseExceptionMapper is an abstract class which implements ExceptionMapper and generates a custom error message which is returned as a Response object. </p>
  
  <p>I'm not sure what I'm doing wrong here.</p>
  
  <p>This is the stacktrace.</p>
  
  <pre><code>java.lang.IllegalArgumentException: Invalid siteKey ONE
      at com.google.common.base.Preconditions.checkArgument(Preconditions.java:148) 
  ..
  </code></pre>