View Javadoc

1   package com.atlassian.plugins.rest.common.error.jersey;
2   
3   import com.atlassian.plugins.rest.common.Status;
4   import com.sun.jersey.api.NotFoundException;
5   
6   import javax.ws.rs.core.Context;
7   import javax.ws.rs.core.Request;
8   import javax.ws.rs.core.Response;
9   import javax.ws.rs.ext.ExceptionMapper;
10  
11  /**
12   * A generic exception mapper that will map {@link NotFoundException not found exceptions}.
13   *
14   * @since 1.0
15   */
16  public class NotFoundExceptionMapper implements ExceptionMapper<NotFoundException> {
17      @Context
18      Request request;
19  
20      public Response toResponse(NotFoundException exception) {
21          return Status.notFound().message(exception.getMessage()).responseBuilder().type(Status.variantFor(request)).build();
22      }
23  }