robe-common/src/main/java/io/robe/common/exception/RobeExceptionMapper.java
@Override
    public Response toResponse(Exception e) {

        String id = System.nanoTime() + "";
        LOGGER.error(id, e);

        if (e instanceof RobeRuntimeException) {
            return ((RobeRuntimeException) e).getResponse(id);
        } else if (e instanceof ConstraintViolationException) {
            ConstraintViolationException exception = (ConstraintViolationException) e;
            RobeMessage[] errors = new RobeMessage[exception.getConstraintViolations().size()];
            int i = 0;
            for (ConstraintViolation error : exception.getConstraintViolations()) {
                errors[i++] = new RobeMessage.Builder().message(error.getMessage()).status(422).id(id).build();
            }
            return Response.status(422).entity(errors).type(MediaType.APPLICATION_JSON).build();
        } else if (e instanceof WebApplicationException) {
            WebApplicationException we = (WebApplicationException) e;
            RobeMessage error = new RobeMessage.Builder().id(id).message(we.getMessage()).status(we.getResponse().getStatus()).build();
            return Response.fromResponse(we.getResponse()).entity(error).type(MediaType.APPLICATION_JSON).build();
        } else {
            if (e.getClass().getName().equals("org.hibernate.exception.ConstraintViolationException")) {
                if (e.getCause() != null && e.getCause().getMessage() != null) {
                    RobeMessage error = new RobeMessage.Builder().message(e.getCause().getMessage().split("for")[0]).status(Response.Status.CONFLICT.getStatusCode()).id(id).build();
                    return Response.status(Response.Status.CONFLICT).entity(error).type(MediaType.APPLICATION_JSON).build();
                }
            }
            RobeMessage error = new RobeMessage.Builder().message(e.getMessage()).id(id).build();
            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).type(MediaType.APPLICATION_JSON).build();
        }
    }
@Override
    public Response toResponse(Exception e) {

        String id = System.nanoTime() + "";
        LOGGER.error(id, e);

        if (e instanceof RobeRuntimeException) {
            return ((RobeRuntimeException) e).getResponse(id);
        } else if (e instanceof ConstraintViolationException) {
            ConstraintViolationException exception = (ConstraintViolationException) e;
            RobeMessage[] errors = new RobeMessage[exception.getConstraintViolations().size()];
            int i = 0;
            for (ConstraintViolation error : exception.getConstraintViolations()) {
                errors[i++] = new RobeMessage.Builder().message(error.getMessage()).status(422).id(id).build();
            }
            return Response.status(422).entity(errors).type(MediaType.APPLICATION_JSON).build();
        } else if (e instanceof WebApplicationException) {
            WebApplicationException we = (WebApplicationException) e;
            RobeMessage error = new RobeMessage.Builder().id(id).message(we.getMessage()).status(we.getResponse().getStatus()).build();
            return Response.fromResponse(we.getResponse()).entity(error).type(MediaType.APPLICATION_JSON).build();
        } else {
            if (e.getClass().getName().equals("org.hibernate.exception.ConstraintViolationException")) {
                if (e.getCause() != null && e.getCause().getMessage() != null) {
                    RobeMessage error = new RobeMessage.Builder().message(e.getCause().getMessage().split("for")[0]).status(Response.Status.CONFLICT.getStatusCode()).id(id).build();
                    return Response.status(Response.Status.CONFLICT).entity(error).type(MediaType.APPLICATION_JSON).build();
                }
            }
            RobeMessage error = new RobeMessage.Builder().message(e.getMessage()).id(id).build();
            return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).type(MediaType.APPLICATION_JSON).build();
        }
    }
@ Override public Response toResponse ( Exception e ) { String id = System . nanoTime ( ) + "" ; LOGGER . error ( id , e ) ; if ( e instanceof RobeRuntimeException ) { return ( ( RobeRuntimeException ) e ) . getResponse ( id ) ; } else if ( e instanceof ConstraintViolationException ) { ConstraintViolationException exception = ( ConstraintViolationException ) e ; RobeMessage [ ] errors = new RobeMessage [ exception . getConstraintViolations ( ) . size ( ) ] ; int i = 0 ; for ( ConstraintViolation error : exception . getConstraintViolations ( ) ) { errors [ i ++ ] = new RobeMessage . Builder ( ) . message ( error . getMessage ( ) ) . status ( 422 ) . id ( id ) . build ( ) ; } return Response . status ( 422 ) . entity ( errors ) . type ( MediaType . APPLICATION_JSON ) . build ( ) ; } else if ( e instanceof WebApplicationException ) { WebApplicationException we = ( WebApplicationException ) e ; RobeMessage error = new RobeMessage . Builder ( ) . id ( id ) . message ( we . getMessage ( ) ) . status ( we . getResponse ( ) . getStatus ( ) ) . build ( ) ; return Response . fromResponse ( we . getResponse ( ) ) . entity ( error ) . type ( MediaType . APPLICATION_JSON ) . build ( ) ; } else { if ( e . getClass ( ) . getName ( ) . equals ( "org.hibernate.exception.ConstraintViolationException" ) ) { if ( e . getCause ( ) != null && e . getCause ( ) . getMessage ( ) != null ) { RobeMessage error = new RobeMessage . Builder ( ) . message ( e . getCause ( ) . getMessage ( ) . split ( "for" ) [ 0 ] ) . status ( Response . Status . CONFLICT . getStatusCode ( ) ) . id ( id ) . build ( ) ; return Response . status ( Response . Status . CONFLICT ) . entity ( error ) . type ( MediaType . APPLICATION_JSON ) . build ( ) ; } } RobeMessage error = new RobeMessage . Builder ( ) . message ( e . getMessage ( ) ) . id ( id ) . build ( ) ; return Response . status ( Response . Status . INTERNAL_SERVER_ERROR ) . entity ( error ) . type ( MediaType . APPLICATION_JSON ) . build ( ) ; } }
Parses or wraps the exception and transforms it to a human readable json loaded response.

@param e Exception to transform
@return error response
Parses or wraps the exception and transforms it to a human readable json loaded response .