X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fadsal%2Fnorthbound%2Fcommons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnorthbound%2Fcommons%2Fexception%2FGenericExceptionMapper.java;fp=opendaylight%2Fadsal%2Fnorthbound%2Fcommons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnorthbound%2Fcommons%2Fexception%2FGenericExceptionMapper.java;h=d2bbfea8700982c5745a6b794ee834b84a4086c6;hb=42c32160bfd41de57189bb246fec5ffb48ed8e9e;hp=0000000000000000000000000000000000000000;hpb=edf5bfcee83c750853253ccfd991ba7000f5f65b;p=controller.git diff --git a/opendaylight/adsal/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/exception/GenericExceptionMapper.java b/opendaylight/adsal/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/exception/GenericExceptionMapper.java new file mode 100644 index 0000000000..d2bbfea870 --- /dev/null +++ b/opendaylight/adsal/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/exception/GenericExceptionMapper.java @@ -0,0 +1,24 @@ +package org.opendaylight.controller.northbound.commons.exception; + +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +@Provider +public class GenericExceptionMapper implements ExceptionMapper { + + @Override + public Response toResponse(Exception exception) { + //check if WebApplicationException and reuse status code + if (exception instanceof WebApplicationException) { + WebApplicationException ex = (WebApplicationException) exception; + return Response.status(ex.getResponse().getStatus()). + entity(ex.getResponse().getEntity()).build(); + } + // throw 500 for all other errors + return Response.status(Response.Status.INTERNAL_SERVER_ERROR). + entity(exception.getMessage()).build(); + } + +}