Merge "Bug 1029: Remove dead code: p2site"
[controller.git] / opendaylight / adsal / northbound / commons / src / main / java / org / opendaylight / controller / northbound / commons / exception / GenericExceptionMapper.java
1 package org.opendaylight.controller.northbound.commons.exception;
2
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;
7
8 @Provider
9 public class GenericExceptionMapper implements ExceptionMapper<Exception> {
10
11     @Override
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();
18         }
19         // throw 500 for all other errors
20         return Response.status(Response.Status.INTERNAL_SERVER_ERROR).
21                 entity(exception.getMessage()).build();
22     }
23
24 }