package io.quarkus.hibernate.orm.rest.data.panache.runtime;

import javax.persistence.PersistenceException;
import javax.transaction.RollbackException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;

import org.hibernate.exception.ConstraintViolationException;

import io.quarkus.arc.ArcUndeclaredThrowableException;
import io.quarkus.rest.data.panache.RestDataPanacheException;

public class RestDataPanacheExceptionMapper implements ExceptionMapper<RestDataPanacheException> {
    @Override
    public Response toResponse(RestDataPanacheException exception) {
        exception.printStackTrace();

        if (exception.getCause() instanceof ArcUndeclaredThrowableException) {
            return toResponse((ArcUndeclaredThrowableException) exception.getCause(), exception.getMessage());
        }
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), exception.getMessage()).build();
    }

    private Response toResponse(ArcUndeclaredThrowableException exception, String message) {
        if (exception.getCause() instanceof RollbackException) {
            return toResponse((RollbackException) exception.getCause(), message);
        }
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), message).build();
    }

    private Response toResponse(RollbackException exception, String message) {
        if (exception.getCause() instanceof PersistenceException) {
            return toResponse((PersistenceException) exception.getCause(), message);
        }
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), message).build();
    }

    private Response toResponse(PersistenceException exception, String message) {
        if (exception.getCause() instanceof ConstraintViolationException) {
            return toResponse((ConstraintViolationException) exception.getCause(), message);
        }
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), message).build();
    }

    private Response toResponse(ConstraintViolationException exception, String message) {
        return Response.status(Response.Status.CONFLICT.getStatusCode(), message).build();
    }
}

@@ -280,16 +280,49 @@
 ception;
+%0Aimport org.jboss.logging.Logger;
 %0A%0Aimport
@@ -540,122 +540,291 @@
     
-@Override%0A    public Response toResponse(RestDataPanacheException exception) %7B%0A        exception.printStackTrac
+private static final Logger LOGGER = Logger.getLogger(RestDataPanacheExceptionMapper.class);%0A%0A    @Override%0A    public Response toResponse(RestDataPanacheException exception) %7B%0A        LOGGER.warnf(exception, %22Mapping an unhandled %25s%22, RestDataPanacheException.class.getSimpleNam
 e()
+)
 ;%0A%0A 

Replace stack trace with a log message