1 package org.opendaylight.controller.northbound.commons.exception;
3 import javax.ws.rs.WebApplicationException;
4 import javax.ws.rs.core.Response;
5 import javax.ws.rs.ext.ExceptionMapper;
6 import javax.ws.rs.ext.Provider;
9 public class GenericExceptionMapper implements ExceptionMapper<Exception> {
12 public Response toResponse(Exception exception) {
13 //check if WebApplicationException and reuse status code
14 if (exception instanceof WebApplicationException) {
15 WebApplicationException ex = (WebApplicationException) exception;
16 return Response.status(ex.getResponse().getStatus()).
17 entity(ex.getResponse().getEntity()).build();
19 // throw 500 for all other errors
20 return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
21 entity(exception.getMessage()).build();