Jersey throws javax.ws.rs.NotFoundException when it cannot find the endpoint. Just use the exception mapper to convert it to the answer of your choice:
import javax.ws.rs.NotFoundException; import javax.ws.rs.core.Response; import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; @Provider public class NotFoundExceptionMapper implements ExceptionMapper<NotFoundException> { public Response toResponse(NotFoundException exception) { return Response.status(Response.Status.NOT_FOUND) .entity("No such resource") .build(); } }
source share