title: Jersey ExceptionMapper not being invoked
body: <p>I am trying to invoke this exception mapper to return a 404 not found response but it keeps returning 500 internal error. Jersey version is 2.22.1. Code snippet below. Appreciate all help. </p>
  
  <p>Thanks.</p>
  
  <p>Exception mapper class.</p>
  
  <pre><code>package org.learn.rest.messengerdemo.exception;
  
  import javax.ws.rs.core.Response;
  import javax.ws.rs.core.Response.Status;
  import javax.ws.rs.ext.ExceptionMapper;
  import javax.ws.rs.ext.Provider;
  
  @Provider
  public class DataNotFoundExceptionMapper implements  ExceptionMapper&lt;DataNotFoundException&gt;{
  
      @Override
      public Response toResponse(DataNotFoundException ex) {
          return Response.status(Response.Status.FORBIDDEN).build();
      }
  }
  </code></pre>
  
  <p>Exception Class.</p>
  
  <p>package org.learn.rest.messengerdemo.exception;</p>
  
  <pre><code>public class DataNotFoundException extends RuntimeException{
  
      private static final long serialVersionUID = 2176642539344388961L;
  
      public DataNotFoundException(String message)
      {
          super(message);
      }
  }
  </code></pre>
  
  <p>Service class's method that throws.</p>
  
  <pre><code>public Message getMessage(long messageId) {
      Message message =  messages.get(messageId);
      if(message == null)
      {
          throw new DataNotFoundException("Message with id " + messageId + " not found");
      }
      return message;
  }
  </code></pre>
  
  <p>And the resource class.</p>
  
  <pre><code>@GET
  @Path("/{messageId}")
  public Message getMessage(@PathParam("messageId") long messageId) {
      return messageService.getMessage(messageId);
  }
  </code></pre>